From 2452849eedf2549e7044523ef0999ca5c06a2903 Mon Sep 17 00:00:00 2001 From: kilbith Date: Sat, 24 Oct 2015 14:14:26 +0200 Subject: [PATCH] Init --- README | 1 - README.md | 4 ++ init.lua | 108 +++++++++++++++++++++++------------------------------- 3 files changed, 49 insertions(+), 64 deletions(-) delete mode 100644 README create mode 100644 README.md diff --git a/README b/README deleted file mode 100644 index 57bca90..0000000 --- a/README +++ /dev/null @@ -1 +0,0 @@ -A mod for Minetest allowing to play a real minigame of Chess (formspec-based). diff --git a/README.md b/README.md new file mode 100644 index 0000000..55cb819 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +A mod for Minetest to play a life-like chess (formspec-based). +Current features: deterministic moves. + +![Preview](http://i.imgur.com/sA3K1rs.png) diff --git a/init.lua b/init.lua index 276f6bb..39b8959 100644 --- a/init.lua +++ b/init.lua @@ -1,3 +1,15 @@ +--[[ TODO: + - Proper black/white ownership by respective player. + - Proper turn by turn handling; + - Proper piece replacement (ie: if piece A eats piece B, piece B is properly replaced without getting a stack under the cursor); + - If a pawn reaches row A or row H -> becomes a queen; + - If one of kings is defeat -> the game stops; + - Actions recording; + - Counter per player. +--]] + + + realchess = {} function realchess.fs(pos) @@ -53,89 +65,66 @@ function realchess.move(pos, from_list, from_index, to_list, to_index, count, pl local pieceTo = inv:get_stack(to_list, to_index):get_name() local pname = player:get_player_name() - --print("Piece: "..piece_a.." | from_list: "..from_list.." | from_index: "..from_index.." | Converted 'from_list':"..string.byte(from_list)) - --print("Piece: "..piece_b.." | to_list: "..to_list.." | to_index: "..to_index.." | Converted 'to_list':"..string.byte(to_list)) - + --print("Piece From: "..pieceFrom.." | from_list: "..from_list.." | from_index: "..from_index.." | Converted 'from_list':"..string.byte(from_list)) + --print("Piece To: "..pieceTo.." | to_list: "..to_list.." | to_index: "..to_index.." | Converted 'to_list':"..string.byte(to_list)) + + --[[ Bugginess -- Turn by turn if pieceFrom:find("white") and (meta:get_string("lastMove") == "" or meta:get_string("lastMove") == "black") then - if meta:get_string("playerOne") == "" and - meta:get_string("playerTwo") == "" then - meta:set_string("playerOne", pname) - meta:set_string("lastMove", "white") - return 1 - elseif meta:get_string("playerOne") ~= "" and - meta:get_string("playerTwo") == "" then - meta:set_string("playerTwo", pname) - meta:set_string("lastMove", "white") - return 1 - elseif pname ~= meta:get_string("playerOne") or - pname ~= meta:get_string("playerTwo") then - minetest.chat_send_player(pname, "You can't move the pieces of your opponent !") - return 0 - end - return 0 + meta:set_string("lastMove", "white") + meta:set_string("playerOne", pname) -- it's shit + return 1 elseif pieceFrom:find("white") and meta:get_string("lastMove") == "white" then minetest.chat_send_player(pname, "It's not your turn, wait your opponent to play.") return 0 elseif pieceFrom:find("black") and (meta:get_string("lastMove") == "" or meta:get_string("lastMove") == "white") then - if meta:get_string("playerOne") == "" and - meta:get_string("playerTwo") == "" then - meta:set_string("playerOne", pname) - meta:set_string("lastMove", "black") - return 1 - elseif meta:get_string("playerOne") ~= "" and - meta:get_string("playerTwo") == "" then - meta:set_string("playerTwo", pname) - meta:set_string("lastMove", "black") - return 1 - elseif pname ~= meta:get_string("playerOne") or - pname ~= meta:get_string("playerTwo") then - minetest.chat_send_player(pname, "You can't move the pieces of your opponent !") - return 0 - end - return 0 + meta:set_string("lastMove", "black") + meta:set_string("playerTwo", pname) -- it's shit + return 1 elseif pieceFrom:find("black") and meta:get_string("lastMove") == "black" then minetest.chat_send_player(pname, "It's not your turn, wait your opponent to play.") return 0 end - + -- ]] -- Don't replace pieces of same color - if (piece_a:find("white") and piece_b:find("white")) or - (piece_a:find("black") and piece_b:find("black")) then + if (pieceFrom:find("white") and pieceTo:find("white")) or + (pieceFrom:find("black") and pieceTo:find("black")) then return 0 end - + -- DETERMINISTIC MOVING + -- PAWNS if pieceFrom:find("pawn_white") then - if from_index == to_index then - if string.byte(to_list) == string.byte(from_list) - 1 then - return 1 - elseif from_list == 'G' and - string.byte(to_list) == string.byte(from_list) - 2 then - return 1 - end + if from_index == to_index and + inv:get_stack(string.char(string.byte(from_list)-1), from_index):get_name() == "" then + if string.byte(to_list) == string.byte(from_list) - 1 then + return 1 + elseif from_list == 'G' and + string.byte(to_list) == string.byte(from_list) - 2 then + return 1 + end elseif string.byte(from_list) > string.byte(to_list) and (from_index ~= to_index and pieceTo:find("black")) then return 1 end elseif pieceFrom:find("pawn_black") then - if from_index == to_index then - if string.byte(to_list) == string.byte(from_list) + 1 then - return 1 - elseif from_list == 'B' and - string.byte(to_list) == string.byte(from_list) + 2 then - return 1 - end + if from_index == to_index and + inv:get_stack(string.char(string.byte(from_list)+1), from_index):get_name() == "" then + if string.byte(to_list) == string.byte(from_list) + 1 then + return 1 + elseif from_list == 'B' and + string.byte(to_list) == string.byte(from_list) + 2 then + return 1 + end elseif string.byte(from_list) < string.byte(to_list) and (from_index ~= to_index and pieceTo:find("white")) then return 1 end - return 0 end @@ -150,7 +139,6 @@ function realchess.move(pos, from_list, from_index, to_list, to_index, count, pl return 1 end end - return 0 end @@ -167,7 +155,6 @@ function realchess.move(pos, from_list, from_index, to_list, to_index, count, pl return 1 end end - return 0 end @@ -180,7 +167,6 @@ function realchess.move(pos, from_list, from_index, to_list, to_index, count, pl return 1 end end - return 0 end @@ -199,7 +185,6 @@ function realchess.move(pos, from_list, from_index, to_list, to_index, count, pl return 1 end end - return 0 end @@ -216,7 +201,6 @@ function realchess.move(pos, from_list, from_index, to_list, to_index, count, pl string.byte(to_list) == string.byte(from_list) + 1) then return 1 end - return 0 end return 0 @@ -230,12 +214,8 @@ function realchess.fields(pos, formname, fields, sender) -- If someone's playing, nobody except the players can reset the game if fields.new and (meta:get_string("playerOne") == pname or meta:get_string("playerTwo") == pname) then - print(meta:get_string("playerOne")) - print(meta:get_string("playerTwo")) realchess.fs(pos) else - print(meta:get_string("playerOne")) - print(meta:get_string("playerTwo")) minetest.chat_send_player(pname, "You can't reset the game unless if you're playing it.") end end @@ -257,6 +237,8 @@ minetest.register_node("realchess:chessboard", { drawtype = "nodebox", paramtype = "light", paramtype2 = "facedir", + inventory_image = "chessboard_top.png", + wield_image = "chessboard_top.png", tiles = {"chessboard_top.png", "chessboard_top.png", "chessboard_sides.png", "chessboard_sides.png", "chessboard_top.png", "chessboard_top.png"},