예제 #1
0
 public TicTacToeCell(TicTacToeCell cell)
 {
     this.Col             = cell.Col;
     this.Row             = cell.Row;
     this.RowMultiplier   = cell.RowMultiplier;
     this.ColMultiplier   = cell.ColMultiplier;
     this.OwnedByPlayerID = cell.OwnedByPlayerID;
 }
예제 #2
0
        private TicTacToeCell ReadAvailableMoveFromInput(string inputLine)
        {
            var inputs = inputLine.Split(' ');
            int row    = int.Parse(inputs[0]);
            int col    = int.Parse(inputs[1]);

            var c = new TicTacToeCell()
            {
                Row = row,
                Col = col,
            };

            c.Normalize();
            return(c);
        }
예제 #3
0
        //Update our grid to match the last move
        public void ProcessPlayerMove(TicTacToeCell playCell)
        {
            if (!playCell.IsRealMove())
            {
                Log($"Ignoring playcell since it is not a real move: {playCell}"); return;
            }

            if (playCell.OwnedByPlayerID == null)
            {
                throw new Exception("Cannot process move if no owner set");
            }
            var gridCell = _helper.GetCellFromCollection(_grid, playCell.Row, playCell.Col);

            gridCell.OwnedByPlayerID = playCell.OwnedByPlayerID;
            Log($"Updated {gridCell} to be owned by playerID {playCell.OwnedByPlayerID}");
        }
예제 #4
0
        //BOARD READING
        private TicTacToeCell ReadOpponentMove(string inputLine)
        {
            var inputs = inputLine.Split(' ');
            int row    = int.Parse(inputs[0]);
            int col    = int.Parse(inputs[1]);

            var c = new TicTacToeCell()
            {
                Row             = row,
                Col             = col,
                OwnedByPlayerID = TicTacToeCell.EnemyID,
            };

            c.Normalize();
            return(c);
        }
예제 #5
0
 private bool CellCanCompleteLine(TicTacToeCell cell, int playerID)
 {
     //for the row in the cell all items must be playerID OR the current item
     for (int colIdx = 0; colIdx < 3; colIdx++)
     {
         if (cell.Col == colIdx)
         {
             continue;
         }                                                    //Skip myself
         var gridCell = _board.GetBoardCell(cell.Row, colIdx);
         if (gridCell.OwnedByPlayerID != playerID)
         {
             return(false);
         }
     }
     //All elements processed, so it seems this can complete the line
     return(true);
 }
예제 #6
0
 //Helpers to get the corresponding board for a given move
 private TicTacToeBoard GetBoardForCell(TicTacToeCell cell, IEnumerable <TicTacToeBoard> boards)
 {
     return(boards.Single(b => b.BoardRowMultiplier == cell.RowMultiplier && b.BoardColMultiplier == cell.ColMultiplier));
 }