コード例 #1
0
ファイル: Program.cs プロジェクト: Chrisazy/2048Bot
        private static void RunGameIteration(int testTypeNum, Storage storage)
        {
            Game game = new Game(4);
            int?[,] startingBoard = new int?[game.size, game.size];
            for (int i = 0; i < game.size; i++) {
                for (int j = 0; j < game.size; j++) {
                    startingBoard[i, j] = game.Board[i, j];
                }
            }

            //game.DisplayBoard();

            int move = 0;
            int temp = 0; // Means different things dependent on algorithm
            while (game.Running) {
                switch (testTypeNum) {
                    case 0: // Random Simple
                        move = Rand.Next(0, 4);
                        break;
                    case 1: // Random no doubles
                        move = Rand.Next(0, 4);
                        while (move == temp) {
                            move = Rand.Next(0, 4); // Never do the same move twice in a row
                        }
                        temp = move;
                        break;
                    case 2: // Rotate Counter-Clockwise
                        move = (move + 1) % 4;
                        break;
                    case 3: // Rotate Clockwise
                        if (move == 0) move = 4;
                        move = (move - 1) % 4;
                        break;
                    case 4: // Rotate both ways, switching at a constant interval
                        if (temp >= 20)
                            temp = 0;
                        if (temp >= 10)
                            move = (move - 1) % 4;
                        else
                            move = (move + 1) % 4;
                        temp++;
                        break;
                    case 5: // Rotate both ways, switching at a random interval
                        temp = Rand.Next(0, 20);
                        if (temp >= 10) {
                            if (move == 0) move = 4;
                            move = (move - 1) % 4;
                        } else {
                            move = (move + 1) % 4;
                        }
                        break;
                }
                game.MakeMove(move);
            }
            //game.DisplayBoard();
            if (game.Loss) {
                //Console.WriteLine("You lost!");
            } else {
                Console.WriteLine("Something else happened..");
            }
            storage.AddScore(new Score { BestTile = game.CurrentMax, Moves = game.NumberOfMoves, TotalScore = game.TotalScore, Board = game.Board, StartingBoard = startingBoard });
        }