public void expand() { List <Move> moves = game.getAvailableMoves(); foreach (Move move in moves) { BoardGame clone = game.Clone() as BoardGame; if (previousMove != null) { move.setOwner(alternateColour(previousMove.owner)); } else { move.setOwner(colour); } clone.makeMove(move); INode child = new Node(clone, this, move, colour); children.Add(child); } }
public List <INode> process(BoardGame game, PlayerColour colour) { DateTime startTime = DateTime.UtcNow; TimeSpan duration = TimeSpan.FromSeconds(2); INode root = nodeService.createNode(game.Clone() as BoardGame, colour); root.expand(); for (int i = 0; i < 3000; i++) { expansion(traverse(root)); } return(root.getChildren()); }
private void HandleAiMove(Player Ai, BoardGame game, BoardGameDTO result, List <Player> players) { List <INode> nodes = nodeService.process(game, Ai.getColour()); Player next = players.Find(x => !x.getColour().Equals(Ai.getColour())); INode move = Ai.makeMove(game.Clone() as BoardGame, nodes, next.getUserId()); provider.updateUser(Ai.getUserId(), move.getReward()); game.makeMove(move.getMove()); List <List <BoardGame> > board = game.getBoard(); result.lastMove = move.getMove(); result.cur = convertToJObject(next); result.lastMoveRating = move.getReward(); int place = 0; double high = -1; double low = 1; foreach (INode node in nodes) { double reward = node.getReward(); if (reward > high) { high = reward; } if (reward < low) { low = reward; } if (move.getReward() < reward) { place++; } } provider.saveMove(Ai.getUserId(), move.getReward(), place); result.highOption = high; result.lowOption = low; }