Esempio n. 1
0
 public Form1()
 {
     InitializeComponent();
     jeu = new Game();
     GetPictureBoxes();
     RefreshInterface();
 }
Esempio n. 2
0
 static void Main(string[] args)
 {
     Game game = new Game(4);
     game.DisplayBoard();
     while (game.Running) {
         try {
             game.MakeMove(int.Parse(Console.ReadLine()));
             game.DisplayBoard();
         } catch {
             Console.WriteLine("Nope..");
         }
     }
     Console.WriteLine("Number of valid moves made: {0}", game.NumberOfMoves);
     Console.WriteLine("Final Score: {0}!", game.TotalScore);
     Console.WriteLine("Largest tile: {0}!", game.CurrentMax);
     Console.ReadLine();
 }
Esempio n. 3
0
        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 });
        }