Example #1
0
        private void radLabel2_Click(object sender, EventArgs e)
        {
            if (StratigyAlgorithm.SelectedItem == null)
            {
                StratigyAlgorithm.Select();  return;
            }
            if (FirstPlayer.SelectedItem == null)
            {
                FirstPlayer.Select(); return;
            }
            Game.DifficultyLevel level = beginner.IsChecked
                ? Game.DifficultyLevel.Easy
                : medium.IsChecked
                    ? Game.DifficultyLevel.Meduim
                    : Game.DifficultyLevel.Difficult;

            IntelligentAgent agent = StratigyAlgorithm.SelectedItem.Index == 0 ? new IntelligentAgent(level) : new IntelligentAgent(level, true);
            int player             = FirstPlayer.SelectedItem.Index == 0 ? 1 : 2;

            //_game = new Game(level) {NextPlayer = player, Agent = agent};
            //_game = new Game(agent, level,Cell.IntCount) {NextPlayer = player, Agent = agent };
            _game = new Game(level, Cell.IntCount)
            {
                NextPlayer = player, Agent = agent
            };
            _game.Subscribe(this);
            Informant.Text = FirstPlayer.SelectedItem.Index == 0 ? "Computer's Turn" : "Your Turn";
            Curten.Start();
        }
Example #2
0
 private void AllIn_Click(object sender, RoutedEventArgs e)
 {
     if (FirstPlayer.PlacePendingBet(FirstPlayer.Points, this.IsServer))
     {
         PlaceBet_Click(null, null);
     }
 }
Example #3
0
 private void Check_Click(object sender, RoutedEventArgs e)
 {
     if (FirstPlayer.PlacePendingBet(this.PendingPot - FirstPlayer.BetForRound, this.IsServer))
     {
         PlaceBet_Click(null, null);
     }
 }
Example #4
0
 void Start()
 {
     ask       = GameObject.Find("Ask").GetComponent <Ask>();
     fp        = GameObject.Find("FPlayer").GetComponent <FirstPlayer>();
     lives     = 5;
     blockOnMe = false;
 }
Example #5
0
 void Start()
 {
     fp           = GameObject.Find("FPlayer").GetComponent <FirstPlayer>();
     sp           = GameObject.Find("SPlayer").GetComponent <SecondPlayer>();
     isAsking     = false;
     makingChoice = false;
     rightAnswer  = false;
 }
Example #6
0
        public async void StartGame()
        {
            GameStarted = true;
            InitialCheck();
            SetupVersion();
            CurrentTurn = Turn.First;
            await FirstPlayer.Move(this);

            SelectedBoardItem.IsSelected = true;
        }
Example #7
0
        public void RestartGame(int i_SizeOfBoard)
        {
            GameBoard.InitializeTheFirstDefaultMoves(GameBoard, GameBoard.NumOFColumns);
            FirstPlayer.PlayerActivity  = true;
            SecondPlayer.PlayerActivity = true;
            FirstPlayer.ListOfSquares.Clear();
            SecondPlayer.ListOfSquares.Clear();

            FirstPlayer.InitializeFirstMovesForFirstPlayer(i_SizeOfBoard);
            SecondPlayer.InitializeFirstMovesForSecondPlayer(i_SizeOfBoard);
            bool start = IsMoveExist();
        }
Example #8
0
 public void Play(IBoard board)
 {
     if (_turnOfFirstPlayer)
     {
         FirstPlayer.Play(board);
         _turnOfFirstPlayer = false;
     }
     else
     {
         SecondPlayer.Play(board);
         _turnOfFirstPlayer = true;
     }
 }
Example #9
0
        protected GameTurn MakeTurn(Player player, GameTurn lastTurn)
        {
            var p    = (player != null) ? player: FirstPlayer.Invoke();
            var turn = m_gameTurnFactory.Invoke(p, this, lastTurn);

            if (turn != null)
            {
                GameMessages.Emit(GameMessages.Kind.TurnBegin, turn);
                turn.DoTurnBegin();
                m_turns.Add(turn);
            }
            return(turn);
        }
Example #10
0
        public override void AI()
        {
            Player      player    = Main.player[projectile.owner];
            FirstPlayer modPlayer = player.GetModPlayer <FirstPlayer>();

            if (player.dead)
            {
                modPlayer.cacoPet = false;
            }
            if (modPlayer.cacoPet)
            {
                projectile.timeLeft = 2;
            }
        }
Example #11
0
 public BoardData Serialize()
 {
     return(new BoardData()
     {
         Size = $"{Width}x{Height}",
         State = BoardState.Running,
         Rules = null,
         FirstPlayer = FirstPlayer.ToString().ToLower()[0],
         CurrentPlayer = CurrentPlayer.ToString().ToLower()[0],
         Board = ToString(),
         Data = ConvertPiecesToDataArray(_pieces),
         Text = new List <string>(),
         Moves = _moves.Select(m => m.Column + (m.Row * Width)).Reverse().ToList(),
         Version = 1
     });
 }
Example #12
0
        public async void OnSelectedColorChanged()
        {
            if (!GameStarted)
            {
                return;
            }

            if (SelectedColor == null)
            {
                return;
            }

            SelectedBoardItem.Color = SelectedColor.Index;

            var twins = TwinsChecker.FindTightTwins(BoardItems);

            if (twins != null)
            {
                foreach (var item in twins.Item1)
                {
                    item.TwinIndex = 0;
                }

                foreach (var item in twins.Item2)
                {
                    item.TwinIndex = 1;
                }

                MessageBoxService.ShowMessage("Blizniaki wygrały!", "");
                GameStarted = false;
                return;
            }
            else if (CurrentRound >= BoardSize)
            {
                MessageBoxService.ShowMessage("Blizniaki przegrały!", "");
                GameStarted = false;
                return;
            }

            CurrentTurn = Turn.First;

            await FirstPlayer.Move(this);

            SelectedBoardItem.IsSelected = true;

            SelectedColor = null;
        }
Example #13
0
        public void UpdatePlayersScoreAtTheEndOfMatch()
        {
            FirstPlayer.CalcCurrentGameScore();
            SecondtPlayer.CalcCurrentGameScore();
            int currentFirstPlayerScore  = m_FirstPlayer.CurrentGameScore;
            int currentSecondPlayerScore = m_SecondPlayer.CurrentGameScore;
            int differenceScore          = Math.Abs(currentFirstPlayerScore - currentSecondPlayerScore);

            if (currentFirstPlayerScore > currentSecondPlayerScore)
            {
                m_FirstPlayer.TotalScore += differenceScore;
            }
            else
            {
                m_SecondPlayer.TotalScore += differenceScore;
            }
        }
Example #14
0
        public string ReturnDeskAsRawText()
        {
            var deskStatement = "";

            deskStatement += Width + ";";
            deskStatement += Height + ";";
            deskStatement += (CurrentWhiteTurn ? "1" : "0") + ";";
            deskStatement += FirstPlayer.ReturnPlayerAsRawText() + ";";
            deskStatement += SecondPlayer.ReturnPlayerAsRawText() + ";";
            foreach (var cell in Cells)
            {
                deskStatement += cell.ReturnCellAsRawText() + ",";
            }

            deskStatement = deskStatement.Substring(0, deskStatement.Length - 1);
            return(deskStatement);
        }
Example #15
0
        public ActionEnum[] DoAction(FightAction action)
        {
            var resultActions = new ActionEnum[2];
            var botAction     = DoRandomBotAction();

            resultActions[0] = GameProcess(action, botAction);
            resultActions[1] = GameProcess(botAction, action);
            if (resultActions[0] == ActionEnum.Hit)
            {
                SecondPlayer.Hit();
            }
            if (resultActions[1] == ActionEnum.Hit)
            {
                FirstPlayer.Hit();
            }
            CheckWinner();
            return(resultActions);
        }
Example #16
0
        private string PrepareDebugInfo()
        {
            const int labelWidth = -20;

            var main = $"Turn: {Turn}, Score: {Score}, With risk: {WithRisk}, Finished: {Finished}";

            var firstPlayerLabel  = $"First Player{(FirstPlayerTurns ? "(!)" : "")}";
            var secondPlayerLabel = $"Second Player{(FirstPlayerTurns ? "" : "(!)")}";

            var firstPlayer  = $"{firstPlayerLabel + ": ",labelWidth}{FirstPlayer.Join()}";
            var secondPlayer = $"{secondPlayerLabel + ": ",labelWidth}{SecondPlayer.Join()}";
            var deck         = $"{"Deck: ",labelWidth}{Deck}";

            var table = $"{"Table: ",labelWidth}" +
                        $"{string.Join(" ", Table.Select(colorAndRank => $"[{colorAndRank.Key.Name} {colorAndRank.Value}]"))}";

            return(string.Join("\n", main, firstPlayer, secondPlayer, table, deck));
        }
Example #17
0
    private void OnCellClicked(Cell cell)
    {
        if (GameState != GameState.Running || _blockCells || cell.CellState != CellState.Empty)
        {
            return;
        }

        if (CurrentPlayer.PlayerType == PlayerType.Computer)
        {
            _blockCells = true;
        }

        PlaceMark(cell);

        if (CurrentPlayerWins(cell))
        {
            Win();

            CurrentPlayer.Sit();
            if (CurrentPlayer == FirstPlayer)
            {
                SecondPlayer.Death();
            }
            else
            {
                FirstPlayer.Death();
            }

            return;
        }

        if (GameLogic.IsDraw(Cells, boardSize))
        {
            Draw();
            FirstPlayer.Sit();
            SecondPlayer.Sit();
            return;
        }

        CurrentPlayer.Attack();
        ChangePlayer();
    }
Example #18
0
        public void StartEvent(object sender, StartRoundEventArgs args)
        {
            try
            {
                if (args != null && args.TaskPool != null)
                {
                    args.TaskPool.Add(Task.Factory.StartNew(() =>
                    {
                        lock (_SyncLock)
                        {
                            if (args.Token != null && !args.Token.IsCancellationRequested)
                            {
                                RPS firstPlayerRes  = FirstPlayer.Play();
                                RPS secondPlayerRes = SecondPlayer.Play();

                                FirstPlayer.Status  = CheckWin((Int32)firstPlayerRes, (Int32)secondPlayerRes);
                                SecondPlayer.Status = CheckWin((Int32)secondPlayerRes, (Int32)firstPlayerRes);

                                switch (FirstPlayer.Status)
                                {
                                case BET.Win: FirstPlayer.Team.Count++; break;

                                case BET.Lose: SecondPlayer.Team.Count++; break;
                                }

                                //Console.WriteLine("{0} : {1} --- {2} : {3}", FirstPlayer.Name, firstPlayerRes, SecondPlayer.Name, secondPlayerRes);
                            }

                            if (args.CancelTokenSource != null && (FirstPlayer.Team.Count >= args.WinLength || SecondPlayer.Team.Count >= args.WinLength))
                            {
                                args.CancelTokenSource.Cancel();
                            }
                        }
                    }));
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error playing in couple", ex.InnerException);
            }
        }
Example #19
0
 private void SetupVersion()
 {
     if (Version == "Komputer vs. Człowiek")
     {
         FirstPlayer  = new FirstPlayer();
         SecondPlayer = new HumanPlayer();
     }
     else if (Version == "Komputer II vs. Człowiek")
     {
         FirstPlayer  = new BetterFirstPlayer();
         SecondPlayer = new HumanPlayer();
     }
     else if (Version == "Komputer vs. Komputer")
     {
         FirstPlayer  = new FirstPlayer();
         SecondPlayer = new SecondPlayer();
     }
     else
     {
         FirstPlayer  = new BetterFirstPlayer();
         SecondPlayer = new BetterSecondPlayer();
     }
 }
Example #20
0
        private void StartGame()
        {
            Console.Title           = "Chess";
            Console.ForegroundColor = ConsoleColor.White;
            Console.OutputEncoding  = Encoding.UTF8;

            SystemSetting.SetSettingOfFontMsGothic();
            IPlayer peshoPlayer = new FirstPlayer("Pesho", Color.DarkYellow);

            peshoPlayer.SaveCoordinates();

            IPlayer goshoPlayer = new SecondPlayer("Gosho", Color.Yellow);

            goshoPlayer.SaveCoordinates();

            Board board = new Board(peshoPlayer, goshoPlayer, 8);

            painter.DrawBoard(board);

            Controller controller = new Controller(board, painter);

            controller.Start();
        }
Example #21
0
        private void PlaceBet_Click(object sender, RoutedEventArgs e)
        {
            if (FirstPlayer.CanPlaceBet() && (FirstPlayer.BetForRound >= PendingPot) || FirstPlayer.Points < PendingPot)
            {
                // If we're the server, try to place our bet
                var newPending = FirstPlayer.BetForRound;
                if (this.IsServer)// && FirstPlayer.PlaceBet())
                {
                    if (newPending > PendingPot)
                    {
                        PendingPot = newPending;
                    }

                    AdvanceTurn();

                    //PlayerBet(FirstPlayer.BetForRound.ToString(), MyUuid);
                }
                else
                {
                    // If it's still our turn, the server will tell us so on next update
                    FirstPlayer.IsMyTurn = false;

                    // Else send the pending bet
                    Dispatcher.BeginInvoke(new Action(() =>
                    {
                        var newMessage = new Message()
                        {
                            Type = MessageType.Bet, Value = FirstPlayer.BetForRound.ToString(), Uuid = MyUuid
                        };
                        var srl = JsonConvert.SerializeObject(newMessage);

                        Client.Send(srl);
                        Console.WriteLine("Bet");
                    }));
                }
            }
        }
Example #22
0
    public void InitializePlayers(bool firstPlayerHuman, bool secondPlayerHuman)
    {
        if (!FirstPlayer)
        {
            CreateFirstPlayer();
        }
        if (!SecondPlayer)
        {
            CreateSecondPlayer();
        }

        if (firstPlayerHuman)
        {
            FirstPlayer.Initialize("Player 1", PlayerType.Human, CellState.Cross);
        }
        else
        {
            FirstPlayer.Initialize("Computer 1", PlayerType.Computer, CellState.Cross);
        }

        if (secondPlayerHuman)
        {
            SecondPlayer.Initialize("Player 2", PlayerType.Human, CellState.Nought);
        }
        else
        {
            SecondPlayer.Initialize("Computer 2", PlayerType.Computer, CellState.Nought);
        }

        CurrentPlayer = FirstPlayer;

        GameState = GameState.Stop;

        Debug.Log($"FirstPlayer : {FirstPlayer}");
        Debug.Log($"SecondPlayer : {SecondPlayer}");
    }
Example #23
0
 private void Bet25_Click(object sender, RoutedEventArgs e)
 {
     if (FirstPlayer.PlacePendingBet(25, this.IsServer))
     {
     }
 }
Example #24
0
 public void SwitchTurns()
 {
     FirstPlayer.SwitchActivation();
     SecondPlayer.SwitchActivation();
 }
Example #25
0
 public override int GetHashCode()
 {
     return(FirstPlayer.GetHashCode() + SecondPlayer.GetHashCode());
 }
Example #26
0
 // Use this for initialization
 void Start()
 {
     firstPlayer  = FindObjectOfType <FirstPlayer> ();
     secondPlayer = FindObjectOfType <SecondPlayer> ();
 }
Example #27
0
 private void ResetPlayers()
 {
     FirstPlayer.Clear();
     SecondPlayer.Clear();
 }
 private void ResetPlayers()
 {
     FirstPlayer.Reset();
     SecondPlayer.Reset();
 }
Example #29
0
        public bool PlayTurn(int sourceIndex, int targetIndex)
        {
            if (!CurrentPlayer.ValidateTurn(GameDice, GameBoard, sourceIndex, targetIndex))
            {
                return(false);
            }

            if (FirstPlayer.IsPlayerTurn)
            {
                if (FirstPlayer.PlayTurn(sourceIndex, targetIndex, GameBoard))
                {
                    IsTurnStart = false;
                    FirstPlayer.Turns--;
                    if (FirstPlayer.Turns == 0)
                    {
                        SwapTurns();
                    }
                    else if (!GameDice.IsDouble)
                    {
                        if (sourceIndex - targetIndex == GameDice.FirstDice)
                        {
                            GameDice.DisableFirstDice();
                        }
                        else
                        {
                            GameDice.DisableSecondDice();
                        }
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                if (SecondPlayer.PlayTurn(sourceIndex, targetIndex, GameBoard))
                {
                    IsTurnStart = false;
                    SecondPlayer.Turns--;
                    if (SecondPlayer.Turns == 0)
                    {
                        SwapTurns();
                    }
                    else if (!GameDice.IsDouble)
                    {
                        int gameMove;
                        if (sourceIndex == GameBoard.BarSource)
                        {
                            gameMove = targetIndex + 1;
                        }
                        else
                        {
                            gameMove = targetIndex - sourceIndex;
                        }
                        if (gameMove == GameDice.FirstDice)
                        {
                            GameDice.DisableFirstDice();
                        }
                        else
                        {
                            GameDice.DisableSecondDice();
                        }
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Example #30
0
 private void AssignMarks()
 {
     FirstPlayer.AssignMark(MarkTypeEnum.Cross);
     SecondPlayer.AssignMark(MarkTypeEnum.Circle);
 }