示例#1
0
        static int DegreesOfFreedom(SnakeBoard board, string direction)
        {
            int x = board.GetPlayerPosition().x;
            int y = board.GetPlayerPosition().y;
            int newX, newY;

            switch (direction)
            {
            case "right":
                newX = x + 1;
                if (board.CellBlocked(newX, y))
                {
                    return(0);
                }
                return(1 + CellFree(board, newX + 1, y) + CellFree(board, newX, y + 1) + CellFree(board, newX, y - 1));

            case "left":
                newX = x - 1;
                if (board.CellBlocked(newX, y))
                {
                    return(0);
                }
                return(1 + CellFree(board, newX - 1, y) + CellFree(board, newX, y + 1) + CellFree(board, newX, y - 1));

            case "down":
                newY = y + 1;
                if (board.CellBlocked(x, newY))
                {
                    return(0);
                }
                return(1 + CellFree(board, x, newY + 1) + CellFree(board, x + 1, newY) + CellFree(board, x - 1, newY));

            default:     // up
                newY = y - 1;
                if (board.CellBlocked(x, newY))
                {
                    return(0);
                }
                return(1 + CellFree(board, x, newY - 1) + CellFree(board, x + 1, newY) + CellFree(board, x - 1, newY));
            }
        }
示例#2
0
 private static int CellFree(SnakeBoard board, int x, int y)
 {
     return(Convert.ToInt32(!board.CellBlocked(x, y)));
 }