Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- (C) 2012 Sandre S. (firstrname at gmail)
- --
- -- Licensed under the Apache License, Version 2.0 (the "License");
- -- you may not use this file except in compliance with the License.
- -- You may obtain a copy of the License at
- --
- -- http://www.apache.org/licenses/LICENSE-2.0
- --
- -- Unless required by applicable law or agreed to in writing, software
- -- distributed under the License is distributed on an "AS IS" BASIS,
- -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- -- See the License for the specific language governing permissions and
- -- limitations under the License.
- --
- local PIECE_EMPTY = " "
- -- White pieces
- local PIECE_WPAWN = "p"
- local PIECE_WROOK = "r"
- local PIECE_WKNIGHT = "n"
- local PIECE_WBISHOP = "b"
- local PIECE_WQUEEN = "q"
- local PIECE_WKING = "k"
- -- Black pieces
- local PIECE_BPAWN = "P"
- local PIECE_BROOK = "R"
- local PIECE_BKNIGHT = "N"
- local PIECE_BBISHOP = "B"
- local PIECE_BQUEEN = "Q"
- local PIECE_BKING = "K"
- local function newBoard()
- local Board = {}
- for x = 1, 8 do
- Board[x] = {}
- for y = 1, 8 do
- Board[y] = {}
- end
- end
- -- Pawns
- for i = 1, 8 do
- Board[2][i] = PIECE_WPAWN
- Board[7][i] = PIECE_BPAWN
- end
- -- White pieces
- Board[1][1] = PIECE_WROOK
- Board[1][2] = PIECE_WKNIGHT
- Board[1][3] = PIECE_WBISHOP
- Board[1][4] = PIECE_WKING
- Board[1][5] = PIECE_WQUEEN
- Board[1][6] = PIECE_WBISHOP
- Board[1][7] = PIECE_WKNIGHT
- Board[1][8] = PIECE_WROOK
- -- Black pieces
- Board[8][1] = PIECE_BROOK
- Board[8][2] = PIECE_BKNIGHT
- Board[8][3] = PIECE_BBISHOP
- Board[8][4] = PIECE_BQUEEN
- Board[8][5] = PIECE_BKING
- Board[8][6] = PIECE_BBISHOP
- Board[8][7] = PIECE_BKNIGHT
- Board[8][8] = PIECE_BROOK
- return Board
- end
- function chessMove(Board, from, to)
- end
- local BoardTemplate = {}
- BoardTemplate[1] = " |1|2|3|4|5|6|7|8"
- BoardTemplate[2] = "A|$ $ $ $ $ $ $ $"
- BoardTemplate[3] = "B|$ $ $ $ $ $ $ $"
- BoardTemplate[4] = "C|$ $ $ $ $ $ $ $"
- BoardTemplate[5] = "D|$ $ $ $ $ $ $ $"
- BoardTemplate[6] = "E|$ $ $ $ $ $ $ $"
- BoardTemplate[7] = "F|$ $ $ $ $ $ $ $"
- BoardTemplate[8] = "G|$ $ $ $ $ $ $ $"
- BoardTemplate[9] = "H|$ $ $ $ $ $ $ $"
- function renderBoard(Board)
- term.clear()
- term.setCursorPos(1,1)
- local n = 1
- for i = 1, #BoardTemplate do
- local line = BoardTemplate[i]
- if string.match(line, "%$") then
- local P = 0
- line = string.gsub(line, "(%$)", function(c) P = P + 1; return Board[n][P] or " " end)
- n = n + 1
- end
- print(line)
- end
- end
- local b = newBoard()
- renderBoard(b)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement