From 0614c98e2f4ed86d554d53d2a3b627b75939457d Mon Sep 17 00:00:00 2001 From: Aayush Chadha Date: Sat, 15 Dec 2018 03:10:54 +0530 Subject: [PATCH 1/2] Fix msg creation --- lua-agent/mcts/mcts.lua | 5 ++--- lua-agent/protocol.lua | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lua-agent/mcts/mcts.lua b/lua-agent/mcts/mcts.lua index 021f30d..6f1bed6 100644 --- a/lua-agent/mcts/mcts.lua +++ b/lua-agent/mcts/mcts.lua @@ -62,15 +62,14 @@ function MCTS:getMove(state) -- create a list of move-state pairs from all possible legal moves -- A table where k=[the move HOLE] and v=[the resulting state] local possibleStates = {} - local boardCopy = t.deepcopy(state:getBoard()) local sideToMove = state:getSideToMove() local ourSide = state:getOurSide() for z=1,tablelength(legalMoves) do - local newState = Kalah:new(boardCopy, ourSide, sideToMove) + local newState = t.deepcopy(state) -- Create the move message and play it - local randomChangeMSg = protocol.createChangeMsg(legalMoves[z], newState:getBoard()) + local randomChangeMSg = protocol.createChangeMsg(legalMoves[z], newState) local turn = protocol.evaluateStateMsg(randomChangeMSg, newState:getBoard()) -- Update the side in the state diff --git a/lua-agent/protocol.lua b/lua-agent/protocol.lua index 69efe63..0265f54 100644 --- a/lua-agent/protocol.lua +++ b/lua-agent/protocol.lua @@ -67,8 +67,10 @@ function protocol.evaluateStartMsg(message) end end -function protocol.createChangeMsg(move, board) - local boardCopyString = board:toShortString() -- Get the short string of boardCopy +-- This function should take state and move to output a message that can be used to +-- determine the right side to play +function protocol.createChangeMsg(move, state) + local boardCopyString = state:getBoard():toShortString() -- Get the short string of boardCopy -- log.debug('Board after:', boardCopyString) local moveHole = move:getHole() local change = 'CHANGE;' @@ -77,8 +79,21 @@ function protocol.createChangeMsg(move, board) opp = ';OPP', endTurn = ';END' } + + local sideToMove = state:getSideToMove() + + local turn + + if (sideToMove == state:getOurSide()) then + turn = turns.you + elseif(sideToMove == Side:getOpposite(state:getOurSide())) then + turn = turns.opp + else + turn = turns.endTurn + end + -- log.info('Returning msg: ', change .. moveHole .. ';' .. boardString .. ';OPP' .. '\n') - return change .. moveHole .. ';' .. boardCopyString .. ';OPP' .. '\n' + return change .. moveHole .. ';' .. boardCopyString .. turn .. '\n' end function protocol.evaluateStateMsg(message, board) From ed5133e68c8ee818049b759036cdb1fbdee71a33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hendrik=20M=C3=B6lder?= Date: Fri, 14 Dec 2018 23:54:36 +0200 Subject: [PATCH 2/2] Remove empty line --- lua-agent/protocol.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lua-agent/protocol.lua b/lua-agent/protocol.lua index 3739bb5..3d6f6a5 100644 --- a/lua-agent/protocol.lua +++ b/lua-agent/protocol.lua @@ -81,9 +81,8 @@ function protocol.createChangeMsg(move, state) opp = ';OPP', endTurn = ';END' } - - local sideToMove = state:getSideToMove() + local sideToMove = state:getSideToMove() local turn if (sideToMove == state:getOurSide()) then