Esempio n. 1
0
 public void UpdateGui(Gameboard gameboard)
 {
     if (gui.Created)
     {
         gui.BeginInvoke(new InvokeDelegateUpdateGui(gui.UpdateGui), new object[] { gameboard });
     }
 }
Esempio n. 2
0
        public object Clone()
        {
            Gameboard ret = new Gameboard();

            for (int i = 0; i < gameboard.Length; i++)
            {
                for (int j = 0; j < gameboard[i].Length; j++)
                {
                    ret.gameboard[i][j] = (Cell)this.gameboard[i][j].Clone();
                }
            }
            ret.CurrentPlayer = CurrentPlayer;

            return(ret);
        }
Esempio n. 3
0
        public Game(GuiController guiController)
        {
            gameboard = new Gameboard();
            gameLogic = new GameLogic(gameboard);

            // The evaluator class can be used to get a comparison regarding the win rate for several players

            /*evaluator = new Evaluator(this,
             *  new AlphaBetaPlayer(Player.White, 1, new Evaluation(Player.White, 1000, 1500, 50, 50, 0)),
             *  new AlphaBetaPlayer(Player.White, 1, new Evaluation(Player.White, 1000, 2000, 50, 50, 0)));*/
            evaluator = new Evaluator(this);

            this.guiController      = guiController;
            players                 = new AbstractPlayer[NUMBER_OF_PLAYERS];
            timerNextMove           = new Timer(PAUSE_BETWEEN_MOVES);
            timerNextMove.Elapsed  += timerNextMove_Elapsed;
            timerNextMove.AutoReset = false;
        }
Esempio n. 4
0
 public override bool Equals(object obj)
 {
     if (obj is Gameboard)
     {
         Gameboard other = (Gameboard)obj;
         for (int i = 0; i < gameboard.Length; i++)
         {
             for (int j = 0; j < gameboard[i].Length; j++)
             {
                 if (gameboard[i][j].Content != other.gameboard[i][j].Content)
                 {
                     return(false);
                 }
             }
         }
         return(this.CurrentPlayer == other.CurrentPlayer);
     }
     return(false);
 }
Esempio n. 5
0
 public void UpdateGui(Gameboard gameboard)
 {
     foreach (HexdameButton button in playButtons)
     {
         button.Text    = gameboard.GetCell(button.FieldPosition).Content.ToString();
         button.Checked = false;
         if (gameboard.GetCell(button.FieldPosition).ContainsWhite)
         {
             button.BackColor = Color.White;
         }
         else if (gameboard.GetCell(button.FieldPosition).ContainsRed)
         {
             button.BackColor = Color.Red;
         }
         else
         {
             button.BackColor = Color.Transparent;
         }
     }
 }
Esempio n. 6
0
        private void LoadState()
        {
            if (evaluator.IsActive)
            {
                // Too many file accesses
                return;
            }

            try
            {
                using (Stream stream = new FileStream("last_state.xml", FileMode.Open))
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    gameboard = (Gameboard)bf.Deserialize(stream);
                    gameLogic = new GameLogic(gameboard);
                }
            }
            catch (Exception e)
            {
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Resets the game board and players and starts the game
        /// </summary>
        public void NewGame()
        {
            gameboard = new Gameboard();
            gameLogic = new GameLogic(gameboard);

            // Loading of game state disabled

            /*if (firstGame)
             * {
             *  firstGame = false;
             *  LoadState();
             * }*/

            currentRound = 0;

            players[(int)Player.White] = new HumanPlayer(Player.White);
            players[(int)Player.Red]   = new AlphaBetaFinalPlayer(Player.Red, 6);

            guiController.UpdateGui((Gameboard)gameboard.Clone());

            timerNextMove.Stop();
            timerNextMove.Start();
        }
Esempio n. 8
0
 public GameLogic(Gameboard gameboard)
 {
     this.gameboard = gameboard;
 }