Beispiel #1
0
 public MoveScore(MoveScore m)
 {
     // TODO: Complete member initialization
     this.Rotation = m.Rotation;
     this.shape = m.shape;
     this.score = m.score;
     this.rootSquarePlacementX = m.rootSquarePlacementX;
 }
Beispiel #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;
        }
Beispiel #3
0
 public BoardState()
 {
     this.cols = new List<List<bool>>();
     this.totalScore = new MoveScore();
     populateBoard();
 }
Beispiel #4
0
        public int addBlock(MoveScore ms)
        {
            int rowDel = 0;
            var shape = Block.getPiece(ms.shape).rotate(ms.Rotation);
            var col = ms.rootSquarePlacementX.Item1;
            var row = ms.rootSquarePlacementX.Item2;

            foreach (var coord in shape.points)        //place every block in the shape
            {
                addGridBlock(col + coord.Item1, row + coord.Item2);
            }

            foreach (var pt in shape.getUniqueYValues())
            {
                if (isRowClear(pt))
                {
                    rowDel++;
                    clearRow(pt);
                }
            }
            return rowDel;
        }
Beispiel #5
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);
 }