Skip to content

Commit

Permalink
Merge pull request #26 from hendrikmolder/hotfix
Browse files Browse the repository at this point in the history
Fix msg creation
  • Loading branch information
hendrikmolder authored Dec 14, 2018
2 parents 28f9d5a + ed5133e commit 7490935
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
5 changes: 2 additions & 3 deletions lua-agent/mcts/mcts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 20 additions & 3 deletions lua-agent/protocol.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ 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;'
--luacheck: ignore turns
Expand All @@ -77,7 +81,20 @@ function protocol.createChangeMsg(move, board)
opp = ';OPP',
endTurn = ';END'
}
return change .. moveHole .. ';' .. boardCopyString .. ';OPP' .. '\n'

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 .. turn .. '\n'
end

function protocol.evaluateStateMsg(message, board)
Expand Down

0 comments on commit 7490935

Please sign in to comment.