Example #1
0
 /// <summary>
 /// Create a record of new game settings
 /// </summary>
 /// <param name="color">Player color</param>
 /// <param name="engineThinkTimeInMs">Ms to allow the engine to come
 /// up with a best move</param>
 public NewGameInfo(TypeGame type, PieceColor color, int engineThinkTimeInMs)
 {
     typegame    = type;
     playerColor = color;
     thinkTime   = engineThinkTimeInMs;
     fen         = null;
 }
Example #2
0
        private void CommonInit(TypeGame humanType, PieceColor humanColor, int engineThinkTimeInMs)
        {
            playerColor = humanColor; // save the player color
            thinkTime   = engineThinkTimeInMs;
            typeofGame  = humanType;
            checkWhite  = 0;
            checkBlack  = 0;
            // Create the board and view
            board = new ChessBoard(typeofGame);

            // Set the data for the view
            view.ViewData = board;

            // Set the Offset for the view
            view.Offset = new Point(25, 75);

            // Create and initialize the board and view
            view.ViewData = board;

            // Set orientation for black players
            if (playerColor == PieceColor.Black)
            {
                board.Orientation = BoardOrientation.BlackOnBottom;
            }

            // Override the unicode drawing with bmp images
            view.SetBitmapImages(new Bitmap(Properties.Resources.chesspieces), new Size(64, 64));
        }
Example #3
0
        /// <summary>
        /// Create a new position based on a FEN
        /// </summary>
        /// <param name="playerColor">Color for the human player</param>
        /// <param name="fenNotation">FEN string that describes the position
        /// (https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation)</param>
        /// <param name="engineThinkTimeInMs">Time engine is allowed for a move</param>
        public void NewPosition(TypeGame typeofg, PieceColor playerColor, string fenNotation, int engineThinkTimeInMs)
        {
            // Basic setup
            CommonInit(typeofg, playerColor, engineThinkTimeInMs);

            // Initialize board
            board.NewPosition(fenNotation);

            // Initialize the engine with a new position
            UpdateEnginePosition();
        }
 public GameController(IGameSettingsModel gameSettingsModel, TypeGame typeGame)
 {
     SettingsModel  = gameSettingsModel;
     TypeGame       = typeGame;
     _jsonTextAsset = Resources.Load <TextAsset>("data");
     if (_jsonTextAsset == null)
     {
         throw new NullReferenceException("_jsonTextAsset", null);
     }
     GameData = JsonUtility.FromJson <TestAssigment.Data.Data>(_jsonTextAsset.text);
     SetupSettings();
 }
Example #5
0
    public IEnumerator Setup()
    {
        _managerGO = new GameObject();
        yield return(null);

        IGameSettingsModel             gameSettingsModel = new GameSettingsModel();
        TypeGame                       typeGame          = TypeGame.GameWithBuffs;
        Dictionary <int, PlayerEntity> dictionary        = new Dictionary <int, PlayerEntity>();
        IGameController                gameController    = new GameController(gameSettingsModel, typeGame);

        _controller = new PlayerController(dictionary, gameController);
    }
Example #6
0
 /// <summary>
 /// Create a new chess board
 /// </summary>
 public ChessBoard(TypeGame typegame)
 {
     if (typegame == TypeGame.Chess960)
     {
         initialFEN = FEN_Chess960();
     }
     else if (typegame == TypeGame.Clasic || typegame == TypeGame.ThreeCheck)
     {
         initialFEN = InitialFENPosition;
     }
     currentFEN     = initialFEN;
     enPassantValid = false;
     NewGame();
 }
Example #7
0
        /// <summary>
        /// Starts a new game if an engine is loaded
        /// </summary>
        private void NewGame(TypeGame typeofgame, string fen, PieceColor playerColor, int engineThinkTimeInMs)
        {
            if (fullPathToChessExe != null)
            {
                chessGame?.StopEngineSelfPlay();

                // Resize the form if needed
                Size gameSize = ChessGame.RequestedSize;
                ClientSize = gameSize;
                textBoxMoveHistory.Location = new Point(ClientSize.Width - ChessBoardView.MoveHistoryWidthInPixels - 25, 75);
                textBoxMoveHistory.Height   = ChessBoardView.BoardSizeInPixels / 2;
                textBoxMoveHistory.Width    = ChessBoardView.MoveHistoryWidthInPixels;
                textBoxMoveHistory.Font     = new Font("Segoe UI", 8);
                textBoxMoveHistory.Text     = String.Empty;

                // Old game is dead to us
                if (chessGame != null)
                {
                    chessGame.OnChessGameSelfPlayGameOver   -= ChessGameSelfPlayGameOverEventHandler;
                    chessGame.OnChessGameNormalPlayGameOver -= ChessGameNormalPlayGameOverEventHandler;
                }
                chessGame?.Dispose();

                // Now we have the engine path, so create an instance of the game class
                ChessEngineProcessLoader loader = new ChessEngineProcessLoader();
                chessGame = new ChessGame(view, fullPathToChessExe, loader, reduceEngineStrength, Thread.CurrentThread.CurrentCulture);
                chessGame.OnChessGameSelfPlayGameOver   += ChessGameSelfPlayGameOverEventHandler;
                chessGame.OnChessGameNormalPlayGameOver += ChessGameNormalPlayGameOverEventHandler;

                if (fen == String.Empty)
                {
                    chessGame.NewGame(typeofgame, playerColor, engineThinkTimeInMs);
                }
                else
                {
                    chessGame.NewPosition(typeofgame, playerColor, fen, engineThinkTimeInMs);
                }

                // Trigger Paint event (draws the initial board)
                Invalidate();
            }
            else
            {
                // No engine loaded, so no new game can be created.  Inform the user
                MessageBox.Show(this, Properties.Resources.ErrorNoEngineLoaded, Properties.Resources.ErrorTitle,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #8
0
        private void TypeGameMenu()
        {
            bool back = false;

            do
            {
                Console.Clear();
                //                                  10        20        30        40
                //                        0123456789012345678901234567890123456789012
                Console.WriteLine(/*00*/ $"┌─────────────────────────────────────────┐");
                Console.WriteLine(/*01*/ $"│        3 en raya (Michi) - Type         │");
                Console.WriteLine(/*02*/ $"├─────────────────────────────────────────┤");
                Console.WriteLine(/*03*/ $"│                                         │");
                Console.WriteLine(/*04*/ $"│ {(typeGame == TypeGame.VsComputer ? "->" : "  ")}(1) - VsComputer".PadRight(42, ' ') + "│");
                Console.WriteLine(/*05*/ $"│ {(typeGame == TypeGame.VsPlayer ? "->" : "  ")}(2) - VsPlayer".PadRight(42, ' ') + "│");
                Console.WriteLine(/*06*/ $"│   (0) - Cancel                          │");
                Console.WriteLine(/*07*/ $"│                                         │");
                Console.WriteLine(/*08*/ $"├─────────────────────────────────────────┤");
                Console.WriteLine(/*09*/ $"│   Choose your option :                  │");
                Console.WriteLine(/*10*/ $"└─────────────────────────────────────────┘");
                Console.SetCursorPosition(25, 9);

                string opt = Console.ReadLine();

                switch (opt)
                {
                case "0":
                    back = true;
                    break;

                case "1":
                    typeGame     = TypeGame.VsComputer;
                    AutoaticTurn = true;
                    back         = true;
                    break;

                case "2":
                    typeGame     = TypeGame.VsPlayer;
                    AutoaticTurn = false;
                    back         = true;
                    break;

                default:
                    break;
                }
            } while (!back);
        }
Example #9
0
        /// <summary>
        /// Create a new game
        /// </summary>
        /// <param name="playerColor">Color for the human player</param>
        /// <param name="engineThinkTimeInMs">Time engine is allowed for a move</param>
        public void NewGame(TypeGame typeofgame, PieceColor playerColor, int engineThinkTimeInMs)
        {
            // Basic setup
            CommonInit(typeofgame, playerColor, engineThinkTimeInMs);

            // Initialize the board
            board.NewGame();

            // Initialize the engine
            engine.ResetBoard();

            // Start the game if the computer goes first
            if (playerColor != PieceColor.White)
            {
                GetBestMoveAsync();
            }
        }
Example #10
0
        /// <summary>
        /// OK button handler
        /// </summary>
        /// <param name="sender">Ignored</param>
        /// <param name="e">Ignored</param>
        private void buttonOk_Click(object sender, EventArgs e)
        {
            // Capture the elements needed for the game
            // 1] Player Color
            PieceColor  playerColor  = PieceColor.White;
            RadioButton playerButton = RadioButtonHelper.GetCheckedRadio(groupBoxPlayerColor);

            // There are only 2 options, so change if it's black
            if (playerButton == radioButtonBlack)
            {
                playerColor = PieceColor.Black;
            }
            RadioButton TypeButton = RadioButtonHelper.GetCheckedRadio(groupBoxTypeGame);
            TypeGame    gametype   = TypeGame.Clasic;

            if (TypeButton == radioButton2)
            {
                gametype = TypeGame.Chess960;
            }
            else if (TypeButton == radioButton3)
            {
                gametype = TypeGame.ThreeCheck;
            }
            else if (TypeButton == radioButton4)
            {
                gametype = TypeGame.KingOfTheHill;
            }
            else if (TypeButton == radioButton5)
            {
                gametype = TypeGame.Custom;
            }
            // 2] Think time for chess engine
            int engineThinkTime = (int)numericUpDownThinkTime.Value;

            newGameInfo = new NewGameInfo(gametype, playerColor, engineThinkTime);

            // 3] Optional FEN
            if (dialogType == NewGameType.PositionalFEN)
            {
                newGameInfo.FEN = textBoxFEN.Text;
            }
            Close();
        }
Example #11
0
        public bool DeleteTypeGame(TypeGame model)
        {
            string nameJanr = model.NameJanr;
            string sql      = "select nameJanr from TypeGame ";

            using (IDbConnection db = new SqlConnection(connectionString))
            {
                IEnumerable <TypeGame> models = db.Query <TypeGame>(sql);

                if (models.Count(item => item.NameJanr == nameJanr) > 0)
                {
                    return(false);
                }

                sql = "DELETE FROM TypeGame WHERE ID = @Id";
                db.Execute(sql, new
                {
                    model.Id
                });
            }
            return(true);
        }
Example #12
0
    public void ApplyBuffsOnPlayer_True_AppliesBuffsOnPlayer()
    {
        // Assign
        Dictionary <int, PlayerEntity> dictionary = new Dictionary <int, PlayerEntity>();

        TypeGame           typeGame          = TypeGame.GameWithBuffs;
        IGameSettingsModel gameSettingsModel = new GameSettingsModel();
        IGameController    gameController    = new GameController(gameSettingsModel, typeGame);
        IBuffCollector     BuffCollector     = new BuffCollector(gameController);
        IPlayerModel       playerModel       = new PlayerModel()
        {
            PlayerPanelHierarchy = new GameObject().AddComponent <PlayerPanelHierarchyBehaviour>(),
            PlayerId             = 1
        };
        PlayerController playerController            = new PlayerController(dictionary, gameController);
        Dictionary <TypeCharacteristic, float> buffs = new Dictionary <TypeCharacteristic, float>();
        Action <Dictionary <TypeCharacteristic, float>, IPlayerModel> callback = new Action <Dictionary <TypeCharacteristic, float>, IPlayerModel>(playerController.IncreasePlayerCharacteristicsValue);

        // Act
        BuffCollector.ApplyBuffsOnPlayer(playerModel, callback);

        // Assert
    }
Example #13
0
        public bool InsertTypeGame(TypeGame model)
        {
            string nameJanr = model.NameJanr;
            string sql      = "select nameJanr from TypeGame ";

            using (IDbConnection db = new SqlConnection(connectionString))
            {
                IEnumerable <TypeGame> models = db.Query <TypeGame>(sql);

                if (models.Count(item => item.NameJanr == nameJanr) > 0)
                {
                    return(false);
                }

                sql = "insert into TypeGame (NameJanr)" +
                      "values (@nameJanr)";
                db.Execute(sql, new
                {
                    model.NameJanr
                });
            }
            return(true);
        }
Example #14
0
 public Football(string name, float price, float diameter, TypeGame game) : base(name, price, diameter)
 {
     Game = game;
 }
Example #15
0
 public GameControllerFactory(TypeGame typeGame)
 {
     GameController = new GameController(new GameSettingsModel(), typeGame);
 }