コード例 #1
0
    private static bool IsTerminalState(Piece[][][] board)
    {
        Match[] matches = BoardChecker.FindMatches(board);
        int     p1Score = matches.Where(match => match.playerNum == 1).Count();
        int     p2Score = matches.Where(match => match.playerNum == 2).Count();

        return(p1Score == 3 || p2Score == 3);
    }
コード例 #2
0
    private static int GetBoardValue(Piece[][][] board)
    {
        Match[] matches = BoardChecker.FindMatches(board);
        int     p1value = matches.Where(match => match.playerNum == 1).Count() * 3;
        int     p2value = matches.Where(match => match.playerNum == 2).Count() * 3;

        p2value = p2value == 9 ? 100 : p2value;
        p1value = p1value == 9 ? 100 : p1value;
        return(p1value - p2value);
    }
コード例 #3
0
    void Start()
    {
        hand            = new GameObject[18]; //change back to 18
        tileDistributor = TileDistributor.Instance();

        //modal planel and options
        modalPanel        = ModalPanel.Instance();
        okayErrorAction   = new UnityAction(ModalPanelErrorOkayAction);
        dealOneTileAction = new UnityAction(TakeOneTile);
        returnTilesAction = new UnityAction(ReturnTilesAction);

        //fill hand randomly
        for (int i = 0; i < hand.Length; i++)
        {
            hand[i] = tileDistributor.DealTile();
        }

        /*use the following to deal a specific hand
         * hand[0] = tileDistributor.DealSpecificTile('M');
         * hand[1] = tileDistributor.DealSpecificTile('E');
         * hand[2] = tileDistributor.DealSpecificTile('L');
         * hand[3] = tileDistributor.DealSpecificTile('T');
         * hand[4] = tileDistributor.DealSpecificTile('S');
         * hand[5] = tileDistributor.DealSpecificTile('P');
         * hand[6] = tileDistributor.DealSpecificTile('U');
         * hand[7] = tileDistributor.DealSpecificTile('N');
         * hand[8] = tileDistributor.DealSpecificTile('Q');
         * hand[9] = tileDistributor.DealSpecificTile('I');
         * hand[10] = tileDistributor.DealSpecificTile('E');
         * hand[11] = tileDistributor.DealSpecificTile('T');
         * hand[12] = tileDistributor.DealSpecificTile('E');
         * hand[13] = tileDistributor.DealSpecificTile('R');
         * hand[14] = tileDistributor.DealSpecificTile('B');
         * hand[15] = tileDistributor.DealSpecificTile('A');
         * hand[16] = tileDistributor.DealSpecificTile('R');
         * hand[17] = tileDistributor.DealSpecificTile('L');
         * hand[18] = tileDistributor.DealSpecificTile('A');
         * hand[19] = tileDistributor.DealSpecificTile('C');
         * hand[20] = tileDistributor.DealSpecificTile('K');
         * hand[21] = tileDistributor.DealSpecificTile('D');
         * hand[22] = tileDistributor.DealSpecificTile('N');
         * hand[23] = tileDistributor.DealSpecificTile('O');
         * hand[24] = tileDistributor.DealSpecificTile('D');
         * hand[25] = tileDistributor.DealSpecificTile('S');
         * hand[26] = tileDistributor.DealSpecificTile('O');
         * hand[27] = tileDistributor.DealSpecificTile('W');
         *
         */


        //get boardchecker component
        boardChecker = gameObject.GetComponent(typeof(BoardChecker)) as BoardChecker;
        PlaceHand();
        GetCells();
    }
コード例 #4
0
        private void SolveAndVerifyBoard(string name, IBoard board)
        {
            var solver = SolverCombiner.AllSolvers.Value;

            IEnumerable <BoardChange> changes;

            do
            {
                changes = solver.Solve(board);
                board   = board.ApplyChanges(changes);
            } while (changes.Any());

            Assert.True(BoardChecker.IsBoardCompleted(board), $"Board: {name}\n{BoardASCIIArt.BoardOnlyAsciiArt(board)}");
        }
コード例 #5
0
        public void SolvedBoard2_OnlyFilled_MissingOne2()
        {
            var board = BoardSamples.Board2;

            board = board.ApplyChanges(
                new BoardChange(0, 2, CellState.Filled),
                new BoardChange(1, 0, CellState.Filled),
                new BoardChange(1, 1, CellState.Filled),
                //new BoardChange(2, 0, CellState.Filled),
                new BoardChange(2, 2, CellState.Filled)
                );

            Assert.False(BoardChecker.IsBoardCompleted(board));
        }
コード例 #6
0
ファイル: GameController.cs プロジェクト: jaideng123/TRITIX
    public void CheckMatches(int playerNum)
    {
        Piece[][][] b = BoardStateUtils.GenerateBoardState(_moves);

        Match[] matches = BoardChecker.FindMatches(b);
        Messenger <Match[]> .Broadcast(GameEvent.PIECES_MATCHED, matches);

        Match[] currentPlayerMatches = matches.Where(match => match.playerNum == playerNum).ToArray();
        if (currentPlayerMatches.Length == 3)
        {
            Debug.Log("All Pieces Matched!");
            gameOver = true;
            Messenger <int> .Broadcast(GameEvent.GAME_OVER, playerNum);
        }
    }
コード例 #7
0
        public void SolvedBoard2_AllCellsMarked()
        {
            var board = BoardSamples.Board2;

            board = board.ApplyChanges(
                new BoardChange(0, 0, CellState.Blocked),
                new BoardChange(0, 1, CellState.Blocked),
                new BoardChange(0, 2, CellState.Filled),
                new BoardChange(1, 0, CellState.Filled),
                new BoardChange(1, 1, CellState.Filled),
                new BoardChange(1, 2, CellState.Blocked),
                new BoardChange(2, 0, CellState.Filled),
                new BoardChange(2, 1, CellState.Blocked),
                new BoardChange(2, 2, CellState.Filled)
                );

            Assert.True(BoardChecker.IsBoardCompleted(board));
        }
コード例 #8
0
        /// <summary>
        /// Constructor Board sets default values and prepares console for
        /// unicode
        /// </summary>
        public Board()
        {
            checker     = new BoardChecker();
            convertions = new Convertions();
            // Prepare for unicode encoding
            Render.SetConsoleEncoding();

            // Getting the player symbols (ghost symbols from each player)
            ghostSymsP1 = new Symbols[3]
            {
                Symbols.ghosts1P1, Symbols.ghosts2P1, Symbols.ghosts3P1
            };

            ghostSymsP2 = new Symbols[3]
            {
                Symbols.ghosts1P2, Symbols.ghosts2P2, Symbols.ghosts3P2
            };
        }
コード例 #9
0
    void Start()
    {
        hand            = new GameObject[21];
        tileDistributor = TileDistributor.Instance();

        modalPanel        = ModalPanel.Instance();
        okayErrorAction   = new UnityAction(ModalPanelErrorOkayAction);
        dealOneTileAction = new UnityAction(TakeOneTile);

        for (int i = 0; i < hand.Length; i++)
        {
            hand[i] = tileDistributor.DealTile();
        }

        boardChecker = gameObject.GetComponent(typeof(BoardChecker)) as BoardChecker;
        PlaceHand();
        GetCells();
    }
コード例 #10
0
        public void BoardManagerShouldKnowIfThereIsATie()
        {
            BoardChecker target = new BoardChecker();
            BoardManager board = new BoardManager();
            HumanPlayer playerOne = new HumanPlayer('X');
            ComputerPlayer playerTwo = new ComputerPlayer('O');

            board.LogMove(playerOne.MakeMove(1, 1));
            board.LogMove(playerTwo.MakeMove(0, 0));
            board.LogMove(playerOne.MakeMove(0, 1));
            board.LogMove(playerTwo.MakeMove(2, 1));
            board.LogMove(playerOne.MakeMove(0, 2));
            board.LogMove(playerTwo.MakeMove(2, 0));
            board.LogMove(playerOne.MakeMove(1, 0));
            board.LogMove(playerTwo.MakeMove(1, 2));
            board.LogMove(playerOne.MakeMove(2, 2));

            Assert.AreEqual(true, target.CheckForTie(board.boardArray));
        }
コード例 #11
0
        public void CheckForWinShouldReturnTrueIfThereAreThreeOsInARow()
        {
            BoardChecker target = new BoardChecker();

            //Three Across the Top
            BoardManager board = new BoardManager();
            HumanPlayer playerOne = new HumanPlayer('o');
            board.LogMove(playerOne.MakeMove(0, 0));
            board.LogMove(playerOne.MakeMove(1, 0));
            board.LogMove(playerOne.MakeMove(2, 0));
            Assert.AreEqual(true, target.CheckForWin(board.boardArray));

            //Three Across the Middle
            board = new BoardManager();
            board.LogMove(playerOne.MakeMove(0, 1));
            board.LogMove(playerOne.MakeMove(1, 1));
            board.LogMove(playerOne.MakeMove(2, 1));
            Assert.AreEqual(true, target.CheckForWin(board.boardArray));

            //Three Across the Bottom
            board = new BoardManager();
            board.LogMove(playerOne.MakeMove(0, 2));
            board.LogMove(playerOne.MakeMove(1, 2));
            board.LogMove(playerOne.MakeMove(2, 2));
            Assert.AreEqual(true, target.CheckForWin(board.boardArray));

            //Three Down the Left Side
            board = new BoardManager();
            board.LogMove(playerOne.MakeMove(0, 0));
            board.LogMove(playerOne.MakeMove(0, 1));
            board.LogMove(playerOne.MakeMove(0, 2));
            Assert.AreEqual(true, target.CheckForWin(board.boardArray));

            //Three Down the Middle
            board = new BoardManager();
            board.LogMove(playerOne.MakeMove(1, 0));
            board.LogMove(playerOne.MakeMove(1, 1));
            board.LogMove(playerOne.MakeMove(1, 2));
            Assert.AreEqual(true, target.CheckForWin(board.boardArray));

            //Three Down the Right Side
            board = new BoardManager();
            board.LogMove(playerOne.MakeMove(1, 0));
            board.LogMove(playerOne.MakeMove(1, 1));
            board.LogMove(playerOne.MakeMove(1, 2));
            Assert.AreEqual(true, target.CheckForWin(board.boardArray));

            //Three In A Slash
            board = new BoardManager();
            board.LogMove(playerOne.MakeMove(0, 2));
            board.LogMove(playerOne.MakeMove(1, 1));
            board.LogMove(playerOne.MakeMove(2, 0));
            Assert.AreEqual(true, target.CheckForWin(board.boardArray));

            //Three In A Backslash
            board = new BoardManager();
            board.LogMove(playerOne.MakeMove(0, 0));
            board.LogMove(playerOne.MakeMove(1, 1));
            board.LogMove(playerOne.MakeMove(2, 2));
            Assert.AreEqual(true, target.CheckForWin(board.boardArray));
        }