0
我有以下JavaScript代碼:組合多個二維數組
function Board() {
// 2d array of 'Pieces'
this.Map = [
[new Piece(), new Piece(), new Piece()],
[new Piece(), new Piece(), new Piece()],
[new Piece(), new Piece(), new Piece()]
];
// return full 9x9 2d integer array
this.GetDetailedMap = function() {
//?
}
}
function Piece() {
//2d array of integers
this.Layout = [
[1,0,1],
[0,0,0],
[1,0,1]
]
}
function DifferentPiece() {
//2d array of integers
this.Layout = [
[1,0,1,1],
[0,0,0,0],
[0,0,0,0],
[1,0,1,1],
]
}
GetDetailedMap()
什麼是應該做是返回一個9x9的二維數組包括該佈局的每一塊右索引處。
所有的'片'佈局總是正方形。所有作品都可以放大,例如:4x4,6x6等。一件3x3和另外4x4應該是不可能的。
我該如何實現該功能?
編輯: 我接近自己解決它,但我有一些錯誤,我的代碼並不像接受的答案那樣整齊。
你怎麼希望他們結合?有很多方法可以將2d數組組合。你遇到了什麼問題?你怎麼試圖把它們結合起來,爲什麼它不起作用? –