The simplest way – not the best way, mind you, but the simplest – would be to define a table of numbers or strings.
For instance, if your pieces were numbered 1-16, here’s a starting board:
local board = {
{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12},
{13, 14, 15, 16},
}
Now you can access any particular square by specifying it’s row (1 is the top, 4 is the bottom) and column (1 is the left, 4 is the right).
local topLeft = board[1][1] – 1
local topRight = board[1][4] – 4
local bottomLeft = board[4][1] – 13
local bottomRight = board[4][4] – 16
You’d check for winning after every move, and if the numbers were all in the correct place, bring up a “you win” screen.
Of course, if you don’t like numbers, you can use strings instead:
local board = {
{“rook”, “knight”, “king”, “bishop”},
{“pawn”, “pawn”, “pawn”, “pawn”},
{“Pawn”, “Pawn”, “Pawn”, “Pawn”},
{“Bishop”, “King”, “Knight”, “Rook”},
}
In that case, your comparisons would take a TINY bit longer. Numbers are faster than strings.
A neat lua trick: to swap two variables, you can use this syntax:
x,y = y,x
In your case, that would allow you to swap pieces with:
board[i][j],board[x][y] = board[x][y],board[i][j]
Good luck! [import]uid: 75168 topic_id: 12599 reply_id: 48291[/import]