예제 #1
0
        public void UpdateAvailableMovesList(Player i_Player)
        {
            eKindOfCell      playersColor = i_Player.DiskColor;
            List <Direction> foundDirection;
            bool             isMoveAvailable;
            PickedCell       foundCell = new PickedCell(0, 0);

            if (i_Player.AvailableMoves.Count != 0)
            {
                i_Player.ClearAvailableMovesList();
            }

            for (int i = 1; i < m_BoardMatrix.GetLength(1) - 1; i++)
            {
                for (int j = 1; j < m_BoardMatrix.GetLength(1) - 1; j++)
                {
                    if (m_BoardMatrix[i, j].CellKind == eKindOfCell.Empty)
                    {
                        // list of neighbours, potential for move
                        foundDirection = findFoeNeighbourDirection(playersColor, i, j);
                        if (foundDirection.Count != 0)
                        {
                            isMoveAvailable = findIfThereIsAMove(foundDirection, i, j, playersColor);
                            if (isMoveAvailable)
                            {
                                foundCell.PickARow    = i;
                                foundCell.PickAColumn = j;
                                i_Player.SetNewAvailableMove(foundCell);
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
 public Player()
 {
     m_PlayerName = "Black Player";
     m_PlayerType = ePlayerType.Human;
     m_Score      = 0;
     m_DiskColor  = eKindOfCell.Black;
     m_AvailableMovesForPlayer = new List <PickedCell>();
 }
예제 #3
0
 public Player()
 {
     m_PlayerName = "Black Player";
     m_PlayerType = ePlayerType.Human;
     m_Score = 0;
     m_DiskColor = eKindOfCell.Black;
     m_AvailableMovesForPlayer = new List<PickedCell>();
 }
예제 #4
0
        private void updateBoardAfterAMove(PickedCell i_CellToUpdate, Player i_Player)
        {
            eKindOfCell      playersColor = i_Player.DiskColor;
            List <Direction> foundDirections;

            foundDirections = findFoeNeighbourDirection(playersColor, i_CellToUpdate.PickARow, i_CellToUpdate.PickAColumn);
            flipFoeDisks(foundDirections, i_CellToUpdate.PickARow, i_CellToUpdate.PickAColumn, playersColor);
            m_BoardMatrix[i_CellToUpdate.PickARow, i_CellToUpdate.PickAColumn].CellKind = i_Player.DiskColor;

            UpdateAvailableMovesList(m_BlackPlayer);
            UpdateAvailableMovesList(m_WhitePlayer);
        }
예제 #5
0
파일: Cell.cs 프로젝트: Green88/ReversiGame
 public void ChangeCellKind()
 {
     if(m_CellKind == eKindOfCell.White)
     {
         m_CellKind = eKindOfCell.Black;
     }
     else
     {
         if(m_CellKind == eKindOfCell.Black)
         {
             m_CellKind = eKindOfCell.White;
         }
     }
 }
예제 #6
0
파일: Cell.cs 프로젝트: Green88/ReversiGame
 public void ChangeCellKind()
 {
     if (m_CellKind == eKindOfCell.White)
     {
         m_CellKind = eKindOfCell.Black;
     }
     else
     {
         if (m_CellKind == eKindOfCell.Black)
         {
             m_CellKind = eKindOfCell.White;
         }
     }
 }
예제 #7
0
 public Player(ePlayerType i_PlayerType, eKindOfCell i_DiskColor)
 {
     m_PlayerType = i_PlayerType;
     m_DiskColor = i_DiskColor;
     m_Score = 0;
     m_AvailableMovesForPlayer = new List<PickedCell>();
     if (PlayerType == ePlayerType.Human)
     {
         m_PlayerName = string.Format("{0} Player", DiskColor.ToString());
     }
     else
     {
         m_PlayerName = "Computer";
     }
 }
예제 #8
0
 public Player(ePlayerType i_PlayerType, eKindOfCell i_DiskColor)
 {
     m_PlayerType = i_PlayerType;
     m_DiskColor  = i_DiskColor;
     m_Score      = 0;
     m_AvailableMovesForPlayer = new List <PickedCell>();
     if (PlayerType == ePlayerType.Human)
     {
         m_PlayerName = string.Format("{0} Player", DiskColor.ToString());
     }
     else
     {
         m_PlayerName = "Computer";
     }
 }
예제 #9
0
        private eKindOfCell foeColor(eKindOfCell i_PlayersColor)
        {
            eKindOfCell foeColor = eKindOfCell.Empty;

            if (i_PlayersColor == eKindOfCell.Black)
            {
                foeColor = eKindOfCell.White;
            }
            else
            {
                if (i_PlayersColor == eKindOfCell.White)
                {
                    foeColor = eKindOfCell.Black;
                }
            }

            return(foeColor);
        }
예제 #10
0
        private List <Direction> findFoeNeighbourDirection(eKindOfCell i_CellColor, int i_ICoordinate, int i_JCoordinate)
        {
            List <Direction> directionsList = new List <Direction>();
            Direction        findNeighbour  = new Direction(0, 0);

            // up-left
            if (m_BoardMatrix[i_ICoordinate - 1, i_JCoordinate - 1].CellKind == foeColor(i_CellColor))
            {
                findNeighbour.ISideDirection = -1;
                findNeighbour.JSideDirection = -1;
                directionsList.Add(findNeighbour);
            }

            // up
            if (m_BoardMatrix[i_ICoordinate - 1, i_JCoordinate].CellKind == foeColor(i_CellColor))
            {
                findNeighbour.ISideDirection = -1;
                findNeighbour.JSideDirection = 0;
                directionsList.Add(findNeighbour);
            }

            // up-right
            if (m_BoardMatrix[i_ICoordinate - 1, i_JCoordinate + 1].CellKind == foeColor(i_CellColor))
            {
                findNeighbour.ISideDirection = -1;
                findNeighbour.JSideDirection = 1;
                directionsList.Add(findNeighbour);
            }

            // right
            if (m_BoardMatrix[i_ICoordinate, i_JCoordinate + 1].CellKind == foeColor(i_CellColor))
            {
                findNeighbour.ISideDirection = 0;
                findNeighbour.JSideDirection = 1;
                directionsList.Add(findNeighbour);
            }

            // down-right
            if (m_BoardMatrix[i_ICoordinate + 1, i_JCoordinate + 1].CellKind == foeColor(i_CellColor))
            {
                findNeighbour.ISideDirection = 1;
                findNeighbour.JSideDirection = 1;
                directionsList.Add(findNeighbour);
            }

            // down
            if (m_BoardMatrix[i_ICoordinate + 1, i_JCoordinate].CellKind == foeColor(i_CellColor))
            {
                findNeighbour.ISideDirection = 1;
                findNeighbour.JSideDirection = 0;
                directionsList.Add(findNeighbour);
            }

            // down-left
            if (m_BoardMatrix[i_ICoordinate + 1, i_JCoordinate - 1].CellKind == foeColor(i_CellColor))
            {
                findNeighbour.ISideDirection = 1;
                findNeighbour.JSideDirection = -1;
                directionsList.Add(findNeighbour);
            }

            // down-left
            if (m_BoardMatrix[i_ICoordinate, i_JCoordinate - 1].CellKind == foeColor(i_CellColor))
            {
                findNeighbour.ISideDirection = 0;
                findNeighbour.JSideDirection = -1;
                directionsList.Add(findNeighbour);
            }

            return(directionsList);
        }
예제 #11
0
파일: Cell.cs 프로젝트: Green88/ReversiGame
 public Cell()
 {
     // default
     m_CellKind = eKindOfCell.Empty;
 }
예제 #12
0
        private eKindOfCell foeColor(eKindOfCell i_PlayersColor)
        {
            eKindOfCell foeColor = eKindOfCell.Empty;

            if (i_PlayersColor == eKindOfCell.Black)
            {
                foeColor = eKindOfCell.White;
            }
            else
            {
                if (i_PlayersColor == eKindOfCell.White)
                {
                    foeColor = eKindOfCell.Black;
                }
            }

            return foeColor;
        }
예제 #13
0
        private void flipFoeDisks(List<Direction> i_AvailableDirections, int i_ICoordinate, int i_JCoordinate, eKindOfCell i_CellColor)
        {
            List<Direction> flipDirections = new List<Direction>();

            foreach (Direction val in i_AvailableDirections)
            {
                int iDistance = 0, jDistance = 0;
                Cell checkCell = m_BoardMatrix[i_ICoordinate + val.ISideDirection, i_JCoordinate + val.JSideDirection];

                iDistance += val.ISideDirection;
                jDistance += val.JSideDirection;

                while (checkCell.CellKind == foeColor(i_CellColor))
                {
                    checkCell = m_BoardMatrix[i_ICoordinate + iDistance + val.ISideDirection, i_JCoordinate + jDistance + val.JSideDirection];
                    if (checkCell.CellKind == i_CellColor)
                    {
                        flipDirections.Add(val);
                    }

                    iDistance += val.ISideDirection;
                    jDistance += val.JSideDirection;
                }
            }

            foreach (Direction val in flipDirections)
            {
                int iDistance = 0;
                int jDistance = 0;
                Cell checkCell = m_BoardMatrix[i_ICoordinate + val.ISideDirection, i_JCoordinate + val.JSideDirection];

                iDistance += val.ISideDirection;
                jDistance += val.JSideDirection;

                while (checkCell.CellKind == foeColor(i_CellColor))
                {
                    m_BoardMatrix[i_ICoordinate + iDistance, i_JCoordinate + jDistance].ChangeCellKind();
                    checkCell = m_BoardMatrix[i_ICoordinate + val.ISideDirection + iDistance, i_JCoordinate + val.JSideDirection + jDistance];
                    iDistance += val.ISideDirection;
                    jDistance += val.JSideDirection;
                }
            }
        }
예제 #14
0
        private bool findIfThereIsAMove(List<Direction> i_DirectionList, int i_ICoordinate, int i_JCoordinate, eKindOfCell i_CellColor)
        {
            bool isThereAMove = false;

            foreach (Direction val in i_DirectionList)
            {
                int iDistance = 0, jDistance = 0;
                Cell checkCell = m_BoardMatrix[i_ICoordinate + val.ISideDirection, i_JCoordinate + val.JSideDirection];

                iDistance += val.ISideDirection;
                jDistance += val.JSideDirection;

                while (checkCell.CellKind == foeColor(i_CellColor))
                {
                    checkCell = m_BoardMatrix[i_ICoordinate + iDistance + val.ISideDirection, i_JCoordinate + jDistance + val.JSideDirection];
                    if (checkCell.CellKind == i_CellColor)
                    {
                        isThereAMove = true;
                    }

                    iDistance += val.ISideDirection;
                    jDistance += val.JSideDirection;
                }
            }

            return isThereAMove;
        }
예제 #15
0
        private List<Direction> findFoeNeighbourDirection(eKindOfCell i_CellColor, int i_ICoordinate, int i_JCoordinate)
        {
            List<Direction> directionsList = new List<Direction>();
            Direction findNeighbour = new Direction(0, 0);

            // up-left
            if (m_BoardMatrix[i_ICoordinate - 1, i_JCoordinate - 1].CellKind == foeColor(i_CellColor))
            {
                findNeighbour.ISideDirection = -1;
                findNeighbour.JSideDirection = -1;
                directionsList.Add(findNeighbour);
            }

            // up
            if (m_BoardMatrix[i_ICoordinate - 1, i_JCoordinate].CellKind == foeColor(i_CellColor))
            {
                findNeighbour.ISideDirection = -1;
                findNeighbour.JSideDirection = 0;
                directionsList.Add(findNeighbour);
            }

            // up-right
            if (m_BoardMatrix[i_ICoordinate - 1, i_JCoordinate + 1].CellKind == foeColor(i_CellColor))
            {
                findNeighbour.ISideDirection = -1;
                findNeighbour.JSideDirection = 1;
                directionsList.Add(findNeighbour);
            }

            // right
            if (m_BoardMatrix[i_ICoordinate, i_JCoordinate + 1].CellKind == foeColor(i_CellColor))
            {
                findNeighbour.ISideDirection = 0;
                findNeighbour.JSideDirection = 1;
                directionsList.Add(findNeighbour);
            }

            // down-right
            if (m_BoardMatrix[i_ICoordinate + 1, i_JCoordinate + 1].CellKind == foeColor(i_CellColor))
            {
                findNeighbour.ISideDirection = 1;
                findNeighbour.JSideDirection = 1;
                directionsList.Add(findNeighbour);
            }

            // down
            if (m_BoardMatrix[i_ICoordinate + 1, i_JCoordinate].CellKind == foeColor(i_CellColor))
            {
                findNeighbour.ISideDirection = 1;
                findNeighbour.JSideDirection = 0;
                directionsList.Add(findNeighbour);
            }

            // down-left
            if (m_BoardMatrix[i_ICoordinate + 1, i_JCoordinate - 1].CellKind == foeColor(i_CellColor))
            {
                findNeighbour.ISideDirection = 1;
                findNeighbour.JSideDirection = -1;
                directionsList.Add(findNeighbour);
            }

            // down-left
            if (m_BoardMatrix[i_ICoordinate, i_JCoordinate - 1].CellKind == foeColor(i_CellColor))
            {
                findNeighbour.ISideDirection = 0;
                findNeighbour.JSideDirection = -1;
                directionsList.Add(findNeighbour);
            }

            return directionsList;
        }
예제 #16
0
        private bool findIfThereIsAMove(List <Direction> i_DirectionList, int i_ICoordinate, int i_JCoordinate, eKindOfCell i_CellColor)
        {
            bool isThereAMove = false;

            foreach (Direction val in i_DirectionList)
            {
                int  iDistance = 0, jDistance = 0;
                Cell checkCell = m_BoardMatrix[i_ICoordinate + val.ISideDirection, i_JCoordinate + val.JSideDirection];

                iDistance += val.ISideDirection;
                jDistance += val.JSideDirection;

                while (checkCell.CellKind == foeColor(i_CellColor))
                {
                    checkCell = m_BoardMatrix[i_ICoordinate + iDistance + val.ISideDirection, i_JCoordinate + jDistance + val.JSideDirection];
                    if (checkCell.CellKind == i_CellColor)
                    {
                        isThereAMove = true;
                    }

                    iDistance += val.ISideDirection;
                    jDistance += val.JSideDirection;
                }
            }

            return(isThereAMove);
        }
예제 #17
0
        private void flipFoeDisks(List <Direction> i_AvailableDirections, int i_ICoordinate, int i_JCoordinate, eKindOfCell i_CellColor)
        {
            List <Direction> flipDirections = new List <Direction>();

            foreach (Direction val in i_AvailableDirections)
            {
                int  iDistance = 0, jDistance = 0;
                Cell checkCell = m_BoardMatrix[i_ICoordinate + val.ISideDirection, i_JCoordinate + val.JSideDirection];

                iDistance += val.ISideDirection;
                jDistance += val.JSideDirection;

                while (checkCell.CellKind == foeColor(i_CellColor))
                {
                    checkCell = m_BoardMatrix[i_ICoordinate + iDistance + val.ISideDirection, i_JCoordinate + jDistance + val.JSideDirection];
                    if (checkCell.CellKind == i_CellColor)
                    {
                        flipDirections.Add(val);
                    }

                    iDistance += val.ISideDirection;
                    jDistance += val.JSideDirection;
                }
            }

            foreach (Direction val in flipDirections)
            {
                int  iDistance = 0;
                int  jDistance = 0;
                Cell checkCell = m_BoardMatrix[i_ICoordinate + val.ISideDirection, i_JCoordinate + val.JSideDirection];

                iDistance += val.ISideDirection;
                jDistance += val.JSideDirection;

                while (checkCell.CellKind == foeColor(i_CellColor))
                {
                    m_BoardMatrix[i_ICoordinate + iDistance, i_JCoordinate + jDistance].ChangeCellKind();
                    checkCell  = m_BoardMatrix[i_ICoordinate + val.ISideDirection + iDistance, i_JCoordinate + val.JSideDirection + jDistance];
                    iDistance += val.ISideDirection;
                    jDistance += val.JSideDirection;
                }
            }
        }
예제 #18
0
파일: Cell.cs 프로젝트: Green88/ReversiGame
 public Cell()
 {
     // default
     m_CellKind = eKindOfCell.Empty;
 }