Exemple #1
0
        private bool DoHumanMove()
        {
            var nextHumanMove = PickHumanMove();

            if (nextHumanMove == null)
            {
                return(false);
            }

            if (!GameAnalysis.IsMoveLegal(currentBoardState, nextHumanMove))
            {
                WinnerAvailable?.Invoke(computerPlayer, WinningReason.InvalidMove, nextHumanMove);
                return(false);
            }

            currentBoardState = currentBoardState.ApplyMove(nextHumanMove);
            NewBoardStateAvailable?.Invoke(currentBoardState);

            if (nextHumanMove is Capitulation)
            {
                WinnerAvailable?.Invoke(computerPlayer, WinningReason.Capitulation, null);
            }

            var winner = GameAnalysis.CheckWinningCondition(currentBoardState);

            if (winner != null)
            {
                WinnerAvailable?.Invoke(winner, WinningReason.RegularQuoridorWin, null);
                return(false);
            }

            return(true);
        }
Exemple #2
0
 public void btn_LoadGame(ScriptableGameData gameData)
 {
     LogsManager.ins.ClearLogs();
     LogsManager.ins.AddLog("Gra została załadowana.");
     Scripts.GameData gD = new Scripts.GameData(gameData);
     gameAnalysis = new GameAnalysis(gD);
 }
Exemple #3
0
 public void btn_LoadGame(string xmlFileName)
 {
     LogsManager.ins.ClearLogs();
     LogsManager.ins.AddLog("Gra została załadowana.");
     Scripts.GameData gD = XMLManager.ins.LoadData2(xmlFileName);
     gameAnalysis = new GameAnalysis(gD);
 }
        public Player DetermineWinningPlayer(Game game)
        {
            var winningHand  = new Hand();
            var gameAnalysis = new GameAnalysis();

            gameAnalysis.Analyze(game);

            return(game.Players.Where(p => p.Rank == 1).FirstOrDefault());
        }
Exemple #5
0
    public void btn_CreateGame()
    {
        LogsManager.ins.ClearLogs();
        LogsManager.ins.AddLog("Nowa gra została utworzona.");

        string rowName = rowPlayerField.text;
        string colName = colPlayerField.text;

        byte rowStrategiesCount = byte.Parse(rowPlayerStrategiesTxt.text);
        byte colStrategiesCount = byte.Parse(colPlayerStrategiesTxt.text);

        int[,] matrix = GetRandomMatrix(rowStrategiesCount, colStrategiesCount);

        gameAnalysis = new GameAnalysis(new Scripts.GameData(matrix, rowName, colName));
    }
    private ResultAnalysis Analyze(List <GameResult> gameResults)
    {
        ResultAnalysis output = new ResultAnalysis();


        for (int i = 0; gameResults.Count > i; i++)
        {
            //게임별 GameAnalysis 생성
            GameAnalysis temp = null;

            if (output.gaList.Exists(x => x.gameName.Equals(gameResults[i].name)))//이미 게임이 있음
            {
                temp = output.gaList.Find(x => x.gameName.Equals(gameResults[i].name));

                temp.frequency++;

                //성공 수
                if (gameResults[i].resultValue != Result.Fail)
                {
                    temp.success++;
                }
            }
            else// 없음
            {
                temp = new GameAnalysis(gameResults[i].name, gameResults[i].resultValue);
                output.gaList.Add(temp);
            }

            //총 성공횟수 계산 & 성공 실패 순서
            //각 게임별 Game_Result 생성
            if (gameResults[i].resultValue != Result.Fail)
            {
                output.totalSuccess += 1;

                output.resultList.Add(true);

                output.grList.Add(new Game_Result(gameResults[i].name, true));
            }
            else
            {
                output.resultList.Add(false);

                output.grList.Add(new Game_Result(gameResults[i].name, false));
            }
        }

        //게임 별 연속 수 계산
        for (int i = 0; output.gaList.Count > i; i++)
        {
            int highest = 0;

            int now = 0;

            for (int j = 0; gameResults.Count > j; j++)
            {
                if (output.gaList[i].gameName.Equals(gameResults[j].name))
                {
                    now++;
                }

                else
                {
                    if (highest < now)
                    {
                        highest = now;

                        now = 0;
                    }
                }
            }

            if (highest < now)
            {
                highest = now;

                now = 0;
            }

            output.gaList[i].chain = highest;
        }

        output.finalScore = CalculateEndValue(5, gameResults); // 마지막 결과 계산

        // 최종게임 결과
        if (gameResults[numOfplay - 1].resultValue != Result.Fail)
        {
            output.finalGameResult = true;
        }

        return(output);
    }
Exemple #7
0
        public void Run()
        {
            IsRunning = true;

            NewBoardStateAvailable?.Invoke(currentBoardState);

            var moveCounter = 0;

            while (!stopRunning)
            {
                if (moveCounter >= gameConstraints.MaximalMovesPerPlayer)
                {
                    WinnerAvailable?.Invoke(currentBoardState.TopPlayer.Player, WinningReason.ExceedanceOfMaxMoves);
                }

                var nextBottomPlayerBotMove = GetBottomPlayerBotMove();

                if (nextBottomPlayerBotMove == null)
                {
                    break;
                }

                if (!GameAnalysis.IsMoveLegal(currentBoardState, nextBottomPlayerBotMove))
                {
                    WinnerAvailable?.Invoke(currentBoardState.TopPlayer.Player, WinningReason.InvalidMove);
                    break;
                }

                currentBoardState = currentBoardState.ApplyMove(nextBottomPlayerBotMove);
                NewBoardStateAvailable?.Invoke(currentBoardState);

                if (nextBottomPlayerBotMove is Capitulation)
                {
                    WinnerAvailable?.Invoke(currentBoardState.TopPlayer.Player, WinningReason.Capitulation);
                }

                var winner = GameAnalysis.CheckWinningCondition(currentBoardState);
                if (winner != null)
                {
                    WinnerAvailable?.Invoke(winner, WinningReason.RegularQuoridorWin);
                    break;
                }

                var nextTopPlayerBotMove = GetTopPlayerBotMove();

                if (nextTopPlayerBotMove == null)
                {
                    break;
                }

                if (!GameAnalysis.IsMoveLegal(currentBoardState, nextTopPlayerBotMove))
                {
                    WinnerAvailable?.Invoke(currentBoardState.BottomPlayer.Player, WinningReason.InvalidMove);
                    break;
                }

                currentBoardState = currentBoardState.ApplyMove(nextTopPlayerBotMove);
                NewBoardStateAvailable?.Invoke(currentBoardState);

                if (nextTopPlayerBotMove is Capitulation)
                {
                    WinnerAvailable?.Invoke(currentBoardState.BottomPlayer.Player, WinningReason.Capitulation);
                }

                var winner2 = GameAnalysis.CheckWinningCondition(currentBoardState);
                if (winner2 != null)
                {
                    WinnerAvailable?.Invoke(winner2, WinningReason.RegularQuoridorWin);
                    break;
                }

                moveCounter++;
            }

            IsRunning = false;

            bottomPlayerBot.NextMoveAvailable -= OnNextBottomPlayerBotMoveAvailable;
            topPlayerBot.NextMoveAvailable    -= OnNextTopPlayerBotMoveAvailable;
        }