コード例 #1
0
ファイル: Gameboard.cs プロジェクト: tsschaffert/hexdame
        public void Reset()
        {
            for (int i = 1; i <= FIELD_SIZE; i++)
            {
                for (int j = 1; j <= FIELD_SIZE; j++)
                {
                    Position position = new Position(i, j);
                    if (ValidCell(position))
                    {
                        if (i <= 4 && j <= 4)
                        {
                            GetCell(position).Content = Cell.Occupancy.White;
                        }
                        else if (i >= FIELD_SIZE - 3 && j >= FIELD_SIZE - 3)
                        {
                            GetCell(position).Content = Cell.Occupancy.Red;
                        }
                        else
                        {
                            GetCell(position).Content = Cell.Occupancy.Empty;
                        }
                    }
                }
            }

            CurrentPlayer = Game.Player.White;
        }
コード例 #2
0
 public AlphaBetaQPlayer(Game.Player playerType, int depth)
     : base(playerType)
 {
     this.depth = depth;
     random     = new Random();
     evaluation = new Evaluation(playerType);
 }
コード例 #3
0
ファイル: GameLogic.cs プロジェクト: tsschaffert/hexdame
        public List <Move> GetPossibleCaptureMovesForPosition(Move currentMove, bool king, Position currentPosition)
        {
            List <Move> possibleMoves = new List <Move>();

            Game.Player activePlayer = gameboard.CurrentPlayer;

            if (!gameboard.ValidCell(currentPosition))
            {
                return(possibleMoves);
            }

            Cell currentCell = gameboard.GetCell(currentPosition);

            currentMove.AddPosition(currentPosition);

            // Captures can be made in every direction
            possibleMoves.AddRange(GetPossibleCaptureMovesForPositionAndDirection(currentMove, king, currentPosition, 1, 0));
            possibleMoves.AddRange(GetPossibleCaptureMovesForPositionAndDirection(currentMove, king, currentPosition, 0, 1));
            possibleMoves.AddRange(GetPossibleCaptureMovesForPositionAndDirection(currentMove, king, currentPosition, 1, 1));
            possibleMoves.AddRange(GetPossibleCaptureMovesForPositionAndDirection(currentMove, king, currentPosition, -1, 0));
            possibleMoves.AddRange(GetPossibleCaptureMovesForPositionAndDirection(currentMove, king, currentPosition, 0, -1));
            possibleMoves.AddRange(GetPossibleCaptureMovesForPositionAndDirection(currentMove, king, currentPosition, -1, -1));

            // If no more moves possible, return current move
            if (possibleMoves.Count == 0 && currentMove.GetNumberOfPositions() >= 2)
            {
                possibleMoves.Add((Move)currentMove.Clone());
            }

            currentMove.RemoveLastPosition();

            return(possibleMoves);
        }
コード例 #4
0
ファイル: GameLogic.cs プロジェクト: tsschaffert/hexdame
        public List <Move> GetPossibleMovesForPosition(bool king, Position currentPosition)
        {
            List <Move> possibleMoves = new List <Move>();

            Game.Player activePlayer = gameboard.CurrentPlayer;

            if (!gameboard.ValidCell(currentPosition))
            {
                return(possibleMoves);
            }

            Cell currentCell = gameboard.GetCell(currentPosition);

            int moveDirection = activePlayer == Game.Player.White ? 1 : -1; // Player one moves to top, player two to bottom

            possibleMoves.AddRange(GetPossibleMovesForPositionAndDirection(king, currentPosition, moveDirection, 0));
            possibleMoves.AddRange(GetPossibleMovesForPositionAndDirection(king, currentPosition, 0, moveDirection));
            possibleMoves.AddRange(GetPossibleMovesForPositionAndDirection(king, currentPosition, moveDirection, moveDirection));

            if (king)
            {
                // Test in every direction
                moveDirection *= -1;

                possibleMoves.AddRange(GetPossibleMovesForPositionAndDirection(king, currentPosition, moveDirection, 0));
                possibleMoves.AddRange(GetPossibleMovesForPositionAndDirection(king, currentPosition, 0, moveDirection));
                possibleMoves.AddRange(GetPossibleMovesForPositionAndDirection(king, currentPosition, moveDirection, moveDirection));
            }

            return(possibleMoves);
        }
コード例 #5
0
 protected override void SendPlayerInfoImpl(string[] myRobotNames, string username)
 {
     myPlayer       = new Game.Player(new Robot[0], username);
     opponentPlayer = new Game.Player(new Robot[0], opponentName);
     string[] opponentRobotNames = setupController.opponentSquadPanel.GetSquadRobotNames();
     gameClient.AsLocal().SendLocalGameRequest(myRobotNames, opponentRobotNames, myPlayer.name, opponentPlayer.name, LoadBoard);
 }
コード例 #6
0
        public Game.Session JoinGameSession(Game.Player joiner, Game.Type gameType, int target)
        {
            var gamesOfType = m_matchingSessions.Where((gs) => { return(gs.m_gameType == gameType); });

            int bestTarget = int.MaxValue;

            Game.Session fallbackSession = null;

            var matched = gamesOfType.Where((gs) =>
            {
                int score = gs.MatchScore(joiner);
                if (score <= target)
                {
                    return(true);
                }
                else if (score < bestTarget)
                {
                    bestTarget      = score;
                    fallbackSession = gs;
                }
                return(false);
            });

            if (matched.Count() >= 0)
            {
                return(matched.ElementAt(0));
            }
            return(fallbackSession);
        }
コード例 #7
0
	void Update(){
		if ( nowPlayer != _GetNowPlayer () ) {
			//Debug.Log("record");
			recordCard();
			nowPlayer = _GetNowPlayer();
		}
	}
コード例 #8
0
ファイル: GuiController.cs プロジェクト: tsschaffert/hexdame
 public void UpdateActivePlayer(Game.Player activePlayer)
 {
     if (gui.Created)
     {
         gui.BeginInvoke(new InvokeDelegateUpdateActivePlayer(gui.UpdateActivePlayer), new object[] { activePlayer });
     }
 }
コード例 #9
0
        private CardAction ChooseRandomAction(List <Card> hand, Game state, Game.Player activePlayer)
        {
            var actions = PossiblePlaysFromState(hand, state, activePlayer);

            // todo, choose the card the definitely leads to victory, or twice luckier to play then drop
            return(actions.ElementAt(Rand.Next(0, actions.Count)));
        }
コード例 #10
0
 public AlphaBetaQPlayer(Game.Player playerType, int depth, Evaluation evaluation)
     : base(playerType)
 {
     this.depth      = depth;
     random          = new Random();
     this.evaluation = evaluation;
 }
コード例 #11
0
ファイル: GameLogic.cs プロジェクト: tsschaffert/hexdame
        /// <summary>
        /// Returns all possible moves
        /// </summary>
        public List <Move> GetPossibleWithoutLookingAtMaxCaptures()
        {
            List <Move> possibleMoves = new List <Move>();

            Game.Player activePlayer = gameboard.CurrentPlayer;

            // Iterate over game board
            for (int i = 1; i <= Gameboard.FIELD_SIZE; i++)
            {
                for (int j = 1; j <= Gameboard.FIELD_SIZE; j++)
                {
                    Position currentPosition = new Position(i, j);

                    if (gameboard.ValidCell(currentPosition))
                    {
                        Cell currentCell = gameboard.GetCell(currentPosition);
                        // Player man on current position?
                        if ((currentCell.ContainsWhite && activePlayer == Game.Player.White) ||
                            (currentCell.ContainsRed && activePlayer == Game.Player.Red))
                        {
                            bool king = currentCell.ContainsKing;
                            // Get all non-capture moves
                            possibleMoves.AddRange(GetPossibleMovesForPosition(king, currentPosition));
                            // Get all capture moves (recursivly)
                            possibleMoves.AddRange(GetPossibleCaptureMovesForPosition(new Move(), king, currentPosition));
                        }
                    }
                }
            }

            return(possibleMoves);
        }
コード例 #12
0
 /*! 相反する2方向を表すキーを受け取り、移動方向を返す
  *  @param[in]  (右, 左), (下, 上), (前方, 後方)など
  *  @return     e.g.CounterDir2Value(右キー, 左キー)
  *      右キーのみ押下 :  1
  *      左キーのみ押下 : -1
  *      両キーとも押下 :  0
  */
 private static float CounterDir2Value(
     Game.Player index,
     InputMode?positiveDir,
     InputMode?negativeDir)
 {
     return(InputManager.Get(positiveDir, index)
            - InputManager.Get(negativeDir, index));
 }
コード例 #13
0
 public SimpleMove(
     Game.Player playerID,
     InputMode?left, InputMode?right,
     InputMode?up, InputMode?down,
     InputMode?front, InputMode?back)
     : this(playerID, left, right, up, down, front, back, Vector3.one)
 {
 }
コード例 #14
0
 public AlphaBetaFinalPlayer(Game.Player playerType, int depth)
     : base(playerType)
 {
     this.depth         = depth;
     random             = new Random();
     transpositionTable = new LimitedSizeDictionary <Int64, Transposition>();
     evaluation         = new Evaluation(playerType);
 }
コード例 #15
0
ファイル: Evaluation.cs プロジェクト: tsschaffert/hexdame
        protected int EvaluateMovementForPlayer(Gameboard state, Game.Player player)
        {
            Game.Player oldPlayer = state.CurrentPlayer;
            state.CurrentPlayer = player;

            GameLogic gameLogic = new GameLogic(state);

            var possibleMoves = gameLogic.GetPossibleWithoutLookingAtMaxCaptures();

            if (possibleMoves.Count == 0)
            {
                // No more moves for me
                if (player == playerType)
                {
                    return(GameLogic.LOSS_VALUE);
                }
                // No more moves for the opponent
                else
                {
                    return(GameLogic.WIN_VALUE);
                }
            }

            int menAbleToMove   = 0;
            int kingsAbleToMove = 0;

            Position lastStartPosition = possibleMoves[0].GetStartingPosition();

            if (state.GetCell(lastStartPosition).ContainsKing)
            {
                kingsAbleToMove++;
            }
            else
            {
                menAbleToMove++;
            }

            foreach (Move move in possibleMoves)
            {
                if (move.GetStartingPosition() != lastStartPosition)
                {
                    lastStartPosition = move.GetStartingPosition();

                    if (state.GetCell(lastStartPosition).ContainsKing)
                    {
                        kingsAbleToMove++;
                    }
                    else
                    {
                        menAbleToMove++;
                    }
                }
            }

            state.CurrentPlayer = oldPlayer;

            return(menAbleToMove * weightMovementMan + kingsAbleToMove * weightMovementKing);
        }
コード例 #16
0
ファイル: Evaluation.cs プロジェクト: tsschaffert/hexdame
 public Evaluation(Game.Player playerType, int weightMan, int weightKing, int weightMovementMan, int weightMovementKing, int maxRandom)
     : this(playerType)
 {
     this.weightMan          = weightMan;
     this.weightKing         = weightKing;
     this.weightMovementMan  = weightMovementMan;
     this.weightMovementKing = weightMovementKing;
     this.maxRandom          = maxRandom;
 }
コード例 #17
0
ファイル: MenuForm.cs プロジェクト: kuzawskak/DungeonVandal
        /// <summary>
        /// Konstruktor głównego Form dla całej gry
        /// Na starcie ustawia panel logowania jako aktywny i tworzy instancję gracza
        /// </summary>
        public MenuForm()
        {
            InitializeComponent();
            InitializePanels();

            activePanel = LoginPanel;
            activePanel.Visible = true;
            player = new Game.Player();
        }
コード例 #18
0
        /// <summary>
        /// Konstruktor głównego Form dla całej gry
        /// Na starcie ustawia panel logowania jako aktywny i tworzy instancję gracza
        /// </summary>
        public MenuForm()
        {
            InitializeComponent();
            InitializePanels();

            activePanel         = LoginPanel;
            activePanel.Visible = true;
            player = new Game.Player();
        }
コード例 #19
0
 public async Task <Game?> AddPlayerToGameIfNotThereAsync(string id, Game.Player player)
 {
     return(await _games.FindOneAndUpdate()
            .Filter(b => b.Match(g => g.Id == id && !g.Players.Any(p => p.Id == player.Id) && g.Status == GameStatus.WaitingForPlayers))
            .Update(b => b
                    .Modify(g => g.Push(g => g.Players, player))
                    .Modify(g => g.Inc(g => g.PlayersCount, 1))
                    .Modify(g => g.Inc(g => g.Version, 1)))
            .ExecuteAsync());
 }
コード例 #20
0
ファイル: Program.cs プロジェクト: YachYaroslav/Pokemons
        static void Main(string[] args)
        {
            Game game = new Game();

            game.GetTypeOfHeroes();
            Game.Player winner = game.Play();
            Console.Clear();
            Console.WriteLine("\n\n\n\tПоздровляем! {0} / {1} - победитель!\n\n\n", winner.name, winner.hero.name);
            Console.ReadKey();
        }
コード例 #21
0
        public bool SingleHostSingleJoiner()
        {
            Game.Player    host   = new Game.Player(Guid.NewGuid(), 1);
            Game.Player    joiner = new Game.Player(Guid.NewGuid(), 1);
            SessionManager sm     = new SessionManager();

            sm.HostGameSession(host);
            sm.JoinGameSession(joiner);
            return(false);
        }
コード例 #22
0
ファイル: GameBuilder.cs プロジェクト: molinch/onlineboardz
 private GameBuilder AddPlayer(Game.Player player, int?playOrder = null)
 {
     if (playOrder != null)
     {
         player           = _mapper.Map <Game.Player, Game.Player>(player); // make a copy since we alter it
         player.PlayOrder = playOrder.Value;
     }
     _game.Players.Add(player);
     return(this);
 }
コード例 #23
0
    void IPointerDownHandler.OnPointerDown(PointerEventData eventData)
    {
        if (state == CellState.On)
        {
            return;
        }

        owner = game.CurrentPlayer;
        State = CellState.On;
        game.PressedCell(this);
    }
コード例 #24
0
        public Game.Session HostGameSession(Game.Player host)
        {
            // TODO: make sure host is not already in another game session
            var gs = new Game.Session();

            gs.m_host = host;
            gs.m_players.Add(host);

            m_activeSessions.Add(gs);
            return(gs);
        }
コード例 #25
0
        public Game.Session HostGameSession(Game.Player host, Game.Type gameType, Func <Game.Session> gameSessionFactory)
        {
            // TODO: make sure host is not already in another game session
            var gs = gameSessionFactory();

            gs.m_gameType = gameType;
            gs.m_host     = host;
            gs.m_players.Add(host);

            m_matchingSessions.Add(gs);
            return(gs);
        }
コード例 #26
0
 /* Check map on win (horizontal and vertical, main and sucond diagonal).
  * Parameters: x(column), y(row) for check.
  * Return: player-winner index. Or 0, if nobody won.
  */
 public Game.Player CheckWin(int x, int y)
 {
     Game.Player player = map[x, y];
     if (CheckWinHorizontal(x, y) >= 5 ||
         CheckWinVertical(x, y) >= 5 ||
         CheckWinMainDiagonal(x, y) >= 5 ||
         CheckWinSecDiagonal(x, y) >= 5)
     {
         return(player);
     }
     return(Game.Player.None);
 }
コード例 #27
0
        protected void PlaceDisksOnRow(int count, int row, Board board, Game.Player player, int dx = 0)
        {
            var lowestIndex = count - 1 + dx;

            if (lowestIndex > Board.IndexMaxCols)
            {
                throw new System.IndexOutOfRangeException(nameof(count));
            }

            for (int col = dx; col <= lowestIndex; col++)
            {
                PlaceDisk(row, col, board, player);
            }
        }
コード例 #28
0
        protected void PlaceDisksOnDiagonal(int count, Board board, Game.Player player, int dx = 0)
        {
            var lowestIndex = count - 1 + dx;

            if (lowestIndex > Board.IndexMaxRows)
            {
                throw new System.IndexOutOfRangeException(nameof(count));
            }

            for (int diag = dx; diag <= lowestIndex; diag++)
            {
                PlaceDisk(diag, diag, board, player);
            }
        }
コード例 #29
0
        protected void PlaceDisksOnColumn(int count, int col, Board board, Game.Player player, int dx = 0)
        {
            var lowestIndex = Board.CountMaxRows - (count + dx);

            if (lowestIndex > Board.IndexMaxRows)
            {
                throw new System.IndexOutOfRangeException(nameof(count));
            }

            for (int row = Board.IndexMaxRows - dx; row >= lowestIndex; row--)
            {
                PlaceDisk(row, col, board, player);
            }
        }
コード例 #30
0
    public void InitializeUI(Game.Player myPlayer, Game.Player opponentPlayer)
    {
        SetOpponentPlayerPanel(opponentPlayer);
        SetMyPlayerPanel(myPlayer);

        submitCommands.Deactivate();
        backToPresent.Deactivate();
        stepBackButton.Deactivate();
        stepForwardButton.Deactivate();

        robotButtonContainer.SetButtons(true);
        commandButtonContainer.SetButtons(false);
        directionButtonContainer.SetButtons(false);
    }
コード例 #31
0
    /* Next 4 functions help check board on win situation */
    private int CheckWinHorizontal(int x, int y)
    {
        Game.Player player = map[x, y];
        int         amount = 1;

        for (int i = x + 1; i < Width && map[i, y] == player; i++)
        {
            amount++;
        }
        for (int i = x - 1; i > 0 && map[i, y] == player; i--)
        {
            amount++;
        }
        return(amount);
    }
コード例 #32
0
    private int CheckWinVertical(int x, int y)
    {
        Game.Player player = map[x, y];
        int         amount = 1;

        for (int i = y + 1; i < Height && map[x, i] == player; i++)
        {
            amount++;
        }
        for (int i = y - 1; i > 0 && map[x, i] == player; i--)
        {
            amount++;
        }
        return(amount);
    }
コード例 #33
0
	void Update(){
		if ( nowPlayer != _GetNowPlayer () ) {
			//Debug.Log("record");
			recordCard();
			nowPlayer = _GetNowPlayer();
		}
		if ( deckCount != game.getDeckCount ()) {
			if(deckCount == game.getDeckCount()+1){
				noColor();
			}
			else{
				haveColor();
			}
			deckCount = game.getDeckCount ();
		}
	}
コード例 #34
0
	//-Functions-
	void Start(){
		game = GameObject.Find ("GameManager").GetComponent<Game> ();
		nowPlayer = _GetNowPlayer();
		lastdeckcnt = _GetDeckCount();
	}
コード例 #35
0
	//-Functions-
	void Start(){
		game = GameObject.Find ("GameManager").GetComponent<Game> ();
		nowPlayer = _GetNowPlayer();
	}
コード例 #36
0
        /***************** LOGIN PANEL **********************/
        /// <summary>
        /// Obsługa kliknięcia przycisku logowania
        /// automatycznie player jest rejestrowany
        /// (co oznacza ze przy pierwszym logowaniu tworzone są pliki ustawień dla danego gracza)
        /// </summary>
        /// <param name="sender">przycisk wysyłający sygnał logowania</param>
        /// <param name="e"></param>
        private void loginButton_Click(object sender, EventArgs e)
        {
            player = new Game.Player(usernameTextBox.Text);
            activePanel.Visible = false;
            main_panel.Visible = true;

            //jesli gracz ma zapisane jakies stany gry to odblokuj przycisk ładowania na głownym menu
            IAsyncResult result = StorageDevice.BeginShowSelector(PlayerIndex.One, null, null);
            GameState.GameStateData saved_data = GameState.LoadGameState(result, player.Name);
            if (saved_data.Count == 0)
            {
                //Pierwsze uruchomienie gry ( brak listy najlepszych wynikow dla danego poziomu)
                main_panel.EnableLoadButton(false);
            }
            else
            {
                main_panel.EnableLoadButton(true);
                load_game_panel.InitializeGameStatesList(saved_data);
            }
            SaveOrLoadSettings();
        }