Exemplo n.º 1
0
        static Node[] generateMoves(Node node)
        {
            List <Node> nodes = new List <Node>();

            for (int i = 0; i < 7; i++)
            {
                if (JoinFour.isMoveValid(node.player | node.opponent, i) &&
                    !JoinFour.hasPlayerWon(node.player) &&
                    !JoinFour.hasPlayerWon(node.opponent))
                {
                    nodes.Add(new Node
                    {
                        opponentPlaying = !node.opponentPlaying,
                        player          = (node.opponentPlaying) ?
                                          node.player :
                                          JoinFour.applyMove(node.player, node.opponent, i),
                        opponent = (node.opponentPlaying) ?
                                   JoinFour.applyMove(node.opponent, node.player, i) :
                                   node.opponent,
                        lastMove = i
                    });
                }
            }

            return(nodes.ToArray());
        }
Exemplo n.º 2
0
        public bool submitMove(int x)
        {
            if (!JoinFour.isMoveValid(players[0] | players[1], x))
            {
                return(false);
            }

            if (playerOnePlaying)
            {
                players[0] = JoinFour.applyMove(players[0], players[1], x);
                if (JoinFour.hasPlayerWon(players[0]))
                {
                    gameFinished = true;
                }
                else if (type == GameType.PlayerVsComputer)
                {
                    players[1] = JoinFour.applyMove(
                        players[1],
                        players[0],
                        AIPlayer.generateNextMove(players[1], players[0]));
                    if (JoinFour.hasPlayerWon(players[1]))
                    {
                        gameFinished = true;
                    }
                }
                else
                {
                    playerOnePlaying = false;
                }
            }
            else
            {
                players[1] = JoinFour.applyMove(players[1], players[0], x);
                if (JoinFour.hasPlayerWon(players[1]))
                {
                    gameFinished = true;
                }
                playerOnePlaying = true;
            }

            return(true);
        }