3d ArrayList vs arrayList of stack [英] 3d ArrayList vs arrayList of stack

查看:26
本文介绍了3d ArrayList vs arrayList of stack的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重新创建棋盘游戏.这个棋盘游戏有一个 4x4 的维度,可以用一个 2D 数组列表来表示.然而,我很难做的是决定什么是实现 4x4 棋盘游戏的最佳方法,其中每行和每列可以容纳 4 个项目(以堆栈的方式,其中顶部项目是最大的整数).在这种情况下,堆栈的 2D arraylist 是最有效的,还是 3D arraylist 是要走的路.同样,我将如何初始化整数的 3D 数组列表?谢谢!

I'm trying to recreate a board game. This board game has a 4x4 dimension which can be represented by a 2D arraylist. However, what i'm having difficulty doing is deciding what would be the best method of implementing a 4x4 board game where each row and column can hold 4 items(In the fashion of a stack where the top item is the greatest int). Would a 2D arraylist of stacks be the most efficient in this case, or would a 3D arraylist be the way to go. Similarly, how would I initialize a 3D arraylist of integers? Thanks!

推荐答案

无论哪种方式,效率都会很好,对于您需要用正方形做的事情,做最简单的事情.您会通过 X、Y 坐标引用事物吗?那么您可能只想使用二维瓷砖数组,这样您就可以将事物引用为

Efficiency is going to be fine either way, do whatever is easiest for the kinds of things you need to do with the squares. Will you be referencing things by their X,Y coordinates? Then you might want to just use a 2-d array of tiles, so you can reference things as

tile = board[x][y]

这里假设原点在棋盘的左上角.如果这真的是一个问题,它也非常有效.

This assumes that the origin is at the top-left of the board. It's also very efficient, if that were actually an issue.

这篇关于3d ArrayList vs arrayList of stack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆