Esempio n. 1
0
        /// <summary>
        /// Recupere l'ensemble des mouvements choisis par l'IA
        /// </summary>
        /// <returns>resultat des mouvements</returns>
        public override int[] play(Board board, Player p)
        {
            int[]  res = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
            IntPtr api = createAPI();

            play_Starting(api, board.convertBoardForCpp(), board.SizeBoard, p.NumberPlayer, res);
            removeAPI(api);
            return(res);
        }
Esempio n. 2
0
        /// <summary>
        /// Construit un game
        /// </summary>
        /// <returns><see cref="Diaballik.Game"/></returns>
        /// <exception cref="PlayerNumberException">Nombre de joueur invalide</exception>
        /// <exception cref="PlayerSameColorException">Veuillez choisir des couleurs distinctes</exception>
        public Game build()
        {
            if (player1 == null || player2 == null)
            {
                throw new PlayerNumberException("invalid number players");
            }
            Player p1 = player1.build(1);
            Player p2 = player2.build(2);

            if (p1.Color.Equals(p2.Color))
            {
                throw new PlayerSameColorException("Veuillez choisir des couleurs distinctes");
            }

            Board board = new Board(Properties.DEFAULT_SIZE_BOARD);

            configureBoard(board, p1, p2);

            GameModelDB gameDB = new GameModelDB
            {
                nameP1          = p1.Name,
                colorP1         = "#" + p1.Color.R.ToString("X2") + p1.Color.G.ToString("X2") + p1.Color.B.ToString("X2"),
                numP1           = p1.NumberPlayer,
                typeP1          = p1.getType(),
                numberTurnP1    = 0,
                nbMoveP1        = 0,
                nameP2          = p2.Name,
                colorP2         = "#" + p2.Color.R.ToString("X2") + p2.Color.G.ToString("X2") + p2.Color.B.ToString("X2"),
                numP2           = p2.NumberPlayer,
                typeP2          = p2.getType(),
                numberTurnP2    = 0,
                nbMoveP2        = 0,
                initialBoard    = board.convertBoardForCpp(),
                lastBoard       = board.convertBoardForCpp(),
                turnInformation = new String[0],
                gameStatus      = GameModelDB.GameStatus.STARTING
            };
            int idDB = createGameInDB(gameDB);

            board.MementoManager.setId(idDB);

            return(new Game(board, p1, p2));
        }
Esempio n. 3
0
        /// <summary>
        /// Récupère les coordonnées des destinations possibles de la balle sélectionnées
        /// </summary>
        /// <param name="board">Le plateau</param>
        /// <returns>les coordonnées des destinations possibles de la balle sélectionnées</returns>
        private int[] getPossibleMove(Board board)
        {
            int[]  boardCpp = board.convertBoardForCpp();
            int[]  res      = new int[16];
            IntPtr api      = createAPI();

            play_selectionBall(api, boardCpp, board.SizeBoard, Tile.Piece.Player.NumberPlayer, res);
            removeAPI(api);
            return(res);
        }
Esempio n. 4
0
        /// <summary>
        /// Récupère les coordonnées des destinations possibles de la piece sélectionnées
        /// </summary>
        /// <param name="board">Le plateau</param>
        /// <returns>Les coordonnées des destinations possibles de la pièce</returns>
        private int[] getPossibleMove(Board board)
        {
            int[]  boardCpp = board.convertBoardForCpp();
            int[]  res      = new int[8];
            IntPtr api      = createAPI();

            play_selectionPiece(api, boardCpp, board.SizeBoard, board.getLineTile(Tile), board.getColumnTile(Tile), res);
            removeAPI(api);
            return(res);
        }
Esempio n. 5
0
 /// <summary>
 /// sauvegarde une partie
 /// </summary>
 public void saveGame(bool endGame = false)
 {
     GameModelDB.GameStatus gameStatus = GameModelDB.GameStatus.STARTING;
     if (playerWhoPlay != null)
     {
         gameStatus = (playerWhoPlay.Equals(p1)) ? GameModelDB.GameStatus.TURNPLAYER1 : GameModelDB.GameStatus.TURNPLAYER2;
     }
     if (endGame)
     {
         gameStatus = GameModelDB.GameStatus.FINISHED;
     }
     board.MementoManager.saveData(board.convertBoardForCpp(), p1, p2, gameStatus);
 }