コード例 #1
0
ファイル: GameLogic.cs プロジェクト: rodgerbenham/Yatttg
        private static Constant.GameState CheckColumns(CellManager cm, IMarker m,
                                                       Constant.GameState currentGameState)
        {
            Constant.GameState result = currentGameState;

            if (result == Constant.GameState.Win)
            {
                return(result);
            }

            for (int column = 0; column < Constant.GridSize; column++)
            {
                int cnt = 0;
                for (int row = 0; row < Constant.GridSize; row++)
                {
                    if (cm.Grid[row, column].Marker != null &&
                        cm.Grid[row, column].Marker.Equals(m))
                    {
                        cnt++;
                    }
                }

                if (cnt == Constant.GridSize)
                {
                    return(Constant.GameState.Win);
                }
            }

            return(result);
        }
コード例 #2
0
ファイル: YatttgModel.cs プロジェクト: penzrgb/Yatttg
        Constant.GameState IYatttgFacade.MakeMove(Player player, int position)
        {
            // To match up with internal array range.
            position--;

            // Update the grid
            cm_.SetCellAtIndex(position, player.Marker);

            currentGameState_ = GameLogic.CheckGridForWinner(cm_, player.Marker,
                currentGameState_);

            return currentGameState_;
        }
コード例 #3
0
        Constant.GameState IYatttgFacade.MakeMove(Player player, int position)
        {
            // To match up with internal array range.
            position--;

            // Update the grid
            cm_.SetCellAtIndex(position, player.Marker);

            currentGameState_ = GameLogic.CheckGridForWinner(cm_, player.Marker,
                                                             currentGameState_);

            return(currentGameState_);
        }
コード例 #4
0
ファイル: YatttgModel.cs プロジェクト: penzrgb/Yatttg
        Constant.GameState IYatttgFacade.InitGame(Player p1, Player p2)
        {
            p1_ = p1;
            p2_ = p2;

            // Flip a coin on who should start first.
            p1Turn = RandomFirstTurn();

            // Init grid
            cm_.InitGrid();

            // Game is now running.
            currentGameState_ = Constant.GameState.InProgress;
            return currentGameState_;
        }
コード例 #5
0
ファイル: YatttgModel.cs プロジェクト: penzrgb/Yatttg
        public YatttgModel()
        {
            // Initialize default values.
            p1_ = null;
            p2_ = null;

            // Give Nort and Cross default values.
            Nort = new Nort();
            Cross = new Cross();

            cm_ = new CellManager();

            // Initial state is to get player information.
            currentGameState_ = Constant.GameState.PlayerInfo;
        }
コード例 #6
0
        Constant.GameState IYatttgFacade.InitGame(Player p1, Player p2)
        {
            p1_ = p1;
            p2_ = p2;

            // Flip a coin on who should start first.
            p1Turn = RandomFirstTurn();

            // Init grid
            cm_.InitGrid();

            // Game is now running.
            currentGameState_ = Constant.GameState.InProgress;
            return(currentGameState_);
        }
コード例 #7
0
        public YatttgModel()
        {
            // Initialize default values.
            p1_ = null;
            p2_ = null;

            // Give Nort and Cross default values.
            Nort  = new Nort();
            Cross = new Cross();

            cm_ = new CellManager();

            // Initial state is to get player information.
            currentGameState_ = Constant.GameState.PlayerInfo;
        }
コード例 #8
0
ファイル: GameLogic.cs プロジェクト: rodgerbenham/Yatttg
        private static Constant.GameState CheckDiagonals(CellManager cm, IMarker m,
                                                         Constant.GameState currentGameState)
        {
            Constant.GameState result = currentGameState;

            if (result == Constant.GameState.Win)
            {
                return(result);
            }

            int cnt = 0;

            // Check leading diagonal.
            for (int i = 0; i < Constant.GridSize; i++)
            {
                if (cm.Grid[i, i].Marker != null &&
                    cm.Grid[i, i].Marker.Equals(m))
                {
                    cnt++;
                }
            }

            if (cnt == Constant.GridSize)
            {
                return(Constant.GameState.Win);
            }
            else
            {
                // Reset the counter, check antidiagonal.
                cnt = 0;
                for (int i = 0; i < Constant.GridSize; i++)
                {
                    if (cm.Grid[i, Constant.GridSize - 1 - i].Marker != null &&
                        cm.Grid[i, Constant.GridSize - 1 - i].Marker.Equals(m))
                    {
                        cnt++;
                    }
                }

                if (cnt == Constant.GridSize)
                {
                    return(Constant.GameState.Win);
                }
            }

            // No result was found on the diagonals.
            return(result);
        }
コード例 #9
0
ファイル: GameLogic.cs プロジェクト: rodgerbenham/Yatttg
        internal static Constant.GameState CheckGridForWinner(CellManager cm, IMarker m,
                                                              Constant.GameState currentGameState)
        {
            Constant.GameState result = currentGameState;

            // Check winning conditions for the newly created move
            if (cm.AllocCount == Constant.MaxOptions)
            {
                result = Constant.GameState.Tie;
            }
            else
            {
                // We only need to check the grid for the marker that has
                // just been placed down.
                result = CheckRows(cm, m, result);
                result = CheckColumns(cm, m, result);
                result = CheckDiagonals(cm, m, result);
            }

            return(result);
        }