Example #1
0
 public GameState(GameState g)
 {
     lastPiece = g.lastPiece;
     deck = new List<int>(g.deck);
     hand = new Hashtable(g.hand);
     game = new BoardState(g.game);
     droppedPiece = g.droppedPiece;
 }
Example #2
0
        /// <summary>
        /// Worker Method
        /// Returns a rating based on the quality of a suggested move
        /// </summary>
        /// <param name="shape">The block to place</param>
        /// <param name="col">The column to place it</param>
        /// <returns></returns>
        public MoveScore getScore(int block, int col, int rotation)
        {
            //arbitrary rotation to get to right orientation
            var shape = Block.getPiece(block).rotate(rotation);

            //variable to indicate how far above the first available spot on the column we need to move before we can place the block
            int increment = 0;

            //cheat variable for easy reference to the row number
            var row = (cols[col].Count);

            //checks to catch overflows that sit outside of the grid
            var xBounds = shape.getXBounds();
            var yBounds = shape.getYBounds();
            var lowestX = xBounds.Item1;
            var highestX = xBounds.Item2;

            //Check to see if the shape overflows the sides of the board.
            if ((col + lowestX) < 0 || (col + highestX) > (WIDTH - 1))
            {
                return null;
            }

            int canPlace = 0;
            foreach (var coord in shape.points)        //check to see if we can place every block in the shape
            {
                if (!getGridBlock(col + coord.Item1, row + coord.Item2))
                {
                    canPlace++;     //getGridBlock returned false, meaning no block
                }
                else    //we can't place the block at the lowest height, scoot upwards until we can
                {
                    int canPlaceNew = 0;

                    while (canPlaceNew <= 4)
                    {
                        increment++;

                        foreach (var point in shape.points)        //check to see if we can place every block in the shape
                        {
                            if (!getGridBlock(col + point.Item1, row + point.Item2 + increment))    //shift shape upwards until canPlace
                            {
                                canPlaceNew++;     //getGridBlock returned false, meaning no block
                            }
                            else
                            {
                                break;  //we can't place it, end early to save time
                            }
                        }
                    }

                    break;  //leave loop
                }
            }

            //update the row respectively
            row = (cols[col].Count + increment);

            var score = new MoveScore(block, rotation, 0, col, row);

            //fill scores
            var spaces = 0;
            foreach (var pt in shape.getUniqueXValues())
            {
                spaces += getBuriedWhitespace(col, row);
            }
            score.AddBuriedWhitespaceScore(spaces);

            score.AddHeightScore(row + shape.getHeight() -1);

            var boardCpy = new BoardState(this);
            int cleared = boardCpy.addBlock(score);

            score.AddRowsClearedScore(cleared);

            return score;
        }
Example #3
0
 public GameState(List<int> list)
 {
     deck = new List<int>(list);
     hand = new Hashtable();
     createHand();
     game = new BoardState();
     lastPiece = 0;
     droppedPiece = 0;
 }
Example #4
0
 public BoardState(BoardState b)
 {
     cols = new List<List<bool>>();
     for (int i = 0; i < WIDTH; i++)
     {
         cols.Add(new List<bool>(b.cols[i]));
     }
     this.totalScore = new MoveScore(b.totalScore);
 }