This is a base class for all players. Custom implementations (Human or Computer players) must derive from this class.
Exemplo n.º 1
0
        /// <summary>
        /// Creates new belot game
        /// </summary>
        public BelotGame( Player south, Player east, Player north, Player west )
        {
            _southPlayer = south;
            _eastPlayer = east;
            _northPlayer = north;
            _westPlayer = west;

            _southPlayer.SetPosition( PlayerPosition.South );
            _eastPlayer.SetPosition( PlayerPosition.East );
            _northPlayer.SetPosition( PlayerPosition.North );
            _westPlayer.SetPosition( PlayerPosition.West );

            _firstPlayer = _southPlayer;

            _deals = new List< Deal >();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Constructor for the class. Creates a new deal during the current game.
        /// </summary>
        /// <param name="game"></param>
        /// <param name="firstPlayer"></param>
        internal Deal( BelotGame game, Player firstPlayer )
        {
            this._game = game;
            this._firstPlayer = firstPlayer;

            _mapEqualCombinationToPlayer = new ListDictionary();
            _mapSequentialCombinationToPlayer = new ListDictionary();
            _mapBelotCombinationToPlayer = new ListDictionary();

            _allCards = InitCards();
            _cards = new CardsCollection();

            foreach( Card card in _allCards )
            {
                _cards.Add( card );
            }

            _currentAnnouncement = new Announcement( AnnouncementTypeEnum.Pass, false, false );

            _game.RaiseDealStarted();
        }
Exemplo n.º 3
0
        internal Player EnterBiddingState()
        {
            AnnouncementManager announcementManager = new AnnouncementManager( );

            Player current = this._firstPlayer;
            Announcement announce;

            while( !announcementManager.IsBiddingFinished	)
            {
                announce = current.MakeAnnouncement( announcementManager );

                announcementManager.Add( current, announce );

                _currentAnnouncement = announcementManager.GetLastValidAnnouncement();

                current = _game.GetNextPlayer( current );
            }

            _bidWinner = announcementManager.GetLastBidder();

            return announcementManager.GetLastBidder();
        }
Exemplo n.º 4
0
        private void NextDeal()
        {
            _southPlayer.Cards.Clear();
            _eastPlayer.Cards.Clear();
            _northPlayer.Cards.Clear();
            _westPlayer.Cards.Clear();

            _currentDeal = new Deal( this, _firstPlayer );

            _firstPlayer = GetNextPlayer( _firstPlayer );
            _deals.Add( _currentDeal );
            _currentDeal.DealFirstCards();

            Player winner = _currentDeal.EnterBiddingState();
            if( _currentDeal.CurrentAnnouncement.Type == AnnouncementTypeEnum.Pass )
            {
                _southPlayer.Cards.Clear();
                _eastPlayer.Cards.Clear();
                _northPlayer.Cards.Clear();
                _westPlayer.Cards.Clear();
                FinalizeDeal();
                return;
            }

            RaiseBiddingCompleted( winner, _currentDeal.CurrentAnnouncement );

            _currentDeal.DealRestCards();

            _southPlayer.CardPlayed += new Player.CardPlayedHandler( _currentDeal.PlayerPlayedCard );
            _northPlayer.CardPlayed += new Player.CardPlayedHandler( _currentDeal.PlayerPlayedCard );
            _eastPlayer.CardPlayed += new Player.CardPlayedHandler( _currentDeal.PlayerPlayedCard );
            _westPlayer.CardPlayed += new Player.CardPlayedHandler( _currentDeal.PlayerPlayedCard );

            _currentDeal.EnterPlayingState();
        }
Exemplo n.º 5
0
 /// <summary>
 /// Raises the BiddingCompleted event
 /// </summary>
 protected void RaiseBiddingCompleted( Player winner, Announcement announce )
 {
     if( BiddingCompleted != null )
         {
             BiddingCompleted( winner, announce );
         }
 }
Exemplo n.º 6
0
 internal void SetWinner( Player winner )
 {
     _winner = winner;
 }
Exemplo n.º 7
0
 private void HumanPlayerIsPlaying( Player player, PlayingManager manager )
 {
     SetPlayerActive( player );
     _currentHuman = ( HumanPlayer )player;
 }
Exemplo n.º 8
0
        private bool HumanCardCombinationAnnouncing( Player player, CardCombination combination )
        {
            bool isAnnounced = false;

            _combinationForm.Combination = combination;
            isAnnounced = ( _combinationForm.ShowDialog() == DialogResult.OK );

            if ( isAnnounced )
            {
                CombinationAnnounced( player, combination );
            }

            return isAnnounced;
        }
Exemplo n.º 9
0
 private void DrawCards( Player player, CardsCollection cards )
 {
     switch ( player.Position )
     {
         case PlayerPosition.South:
             _panelSouth.Cards = cards;
             break;
         case PlayerPosition.East:
             _panelEast.Cards = cards;
             break;
         case PlayerPosition.North:
             _panelNorth.Cards = cards;
             break;
         case PlayerPosition.West:
             _panelWest.Cards = cards;
             break;
         default:
             _panelSouth.Cards = cards;
             break;
     }
 }
        /// <summary>
        /// If announcement made by this player is valid according to game rules
        /// </summary>
        public bool IsValid( Player player, AnnouncementTypeEnum type, bool isDoubled, bool isRedoubled )
        {
            //no player
            if( player == null)
                throw new ArgumentNullException( "Player", "Bidding player cannot be null");

            //legal pass
            if( type == AnnouncementTypeEnum.Pass )
            {
                if( !isDoubled && !isRedoubled )
                    return true;
                else
                    return false;
            }

            if( _lastValidAnnouncement.CompareTo( type ) < 0  && !isDoubled && !isRedoubled )
                return true;

            if( _lastValidAnnouncement.CompareTo( type ) == 0 && !IsLastValidBidByTeam( player ) && !_lastValidAnnouncement.IsReDoubled)
            {
                if( !_lastValidAnnouncement.IsDoubled && isDoubled && !isRedoubled )
                    return true;
                if( _lastValidAnnouncement.IsDoubled && !isDoubled && isRedoubled )
                    return true;
            }

            return false;
        }
Exemplo n.º 11
0
        private void PlayerHasTurn( Player player )
        {
            #region Announce combinations on first hand

            if( _playingManager.IsFirstHand && _currentAnnouncement.Type != AnnouncementTypeEnum.NoTrumps )
            {
                CombinationFinder finder = new CombinationFinder( player.Cards );
                foreach( CardCombination combination in finder.Combinations )
                {
                    bool isValidCombination = false;

                    if( combination is SequentialCombination )
                    {
                        Player biggest = FindBiggestSequentialCombinationHolder();
                        CardCombination biggestCombination = null;

                        foreach( DictionaryEntry de in _mapSequentialCombinationToPlayer )
                        {
                            if( biggest == de.Value as Player )
                            {
                                biggestCombination = de.Key as CardCombination;
                                break;
                            }
                        }

                        if( (biggest == null) ||
                            (combination.Points >= biggestCombination.Points) ||
                            (player.Position == biggest.Position || player.Position == _game.GetTeamPlayer( biggest ).Position) )
                        {
                            isValidCombination = true;
                        }
                    }
                    else
                    {
                        isValidCombination = true;
                    }

                    if( isValidCombination && player.AnnounceCombination( combination ) )
                    {
                        if( combination is SequentialCombination )
                        {
                            _mapSequentialCombinationToPlayer.Add( combination, player );
                        }
                        if( combination is FourEqualsCombination )
                        {
                            _mapEqualCombinationToPlayer.Add( combination, player );
                        }
                    }
                }
            }

            #endregion

            foreach( Card card in player.Cards )
            {
                card.IsSelectable = _playingManager.IsValid( player, card );
            }

            player.PlayCard( _playingManager );
        }
Exemplo n.º 12
0
 private int GetCombinationPoints( Player winner, ListDictionary map )
 {
     int points = 0;
     foreach( DictionaryEntry de in map )
     {
         if( winner == de.Value || _game.GetTeamPlayer( winner ) == de.Value )
         {
             points += (de.Key as CardCombination).Points;
             (de.Key as CardCombination).IsCounted = true;
         }
         else
         {
             (de.Key as CardCombination).IsCounted = false;
         }
     }
     return points;
 }
Exemplo n.º 13
0
 private void AddLastTenPoints( Player winner )
 {
     PlayerPosition pos = winner.Position;
     if( pos == PlayerPosition.East || pos == PlayerPosition.West )
     {
         _eastWestPoints += 10;
     }
     else
     {
         _northSouthPoints += 10;
     }
 }
Exemplo n.º 14
0
 private void AddBelotCombination( Player player, BelotCombination combination )
 {
     if( player.AnnounceCombination( combination ) )
     {
         _mapBelotCombinationToPlayer.Add( combination, player );
     }
 }
Exemplo n.º 15
0
        internal void PlayerPlayedCard( Player player, Card playedCard )
        {
            _playingManager.Add( player, playedCard );

            player.Cards.Remove( playedCard );

            foreach( Card card in player.Cards )
            {
                card.IsSelectable = false;
            }

            if( _playingManager.IsHandClosed )
            {
                Hand lastHand = _playingManager.GetLastHand();
                CalculatePoints( lastHand );
                _game.HandIsClosed( lastHand );
                NextHand();
            }
            else
            {
                PlayerHasTurn( _game.GetNextPlayer( player ) );
            }
        }
Exemplo n.º 16
0
        private void CompPlayerBidded( Player player, Announcement currentAnnounce )
        {
            SetPlayerActive( null );

            bool isActive = currentAnnounce.CompareTo( _game.CurrentDeal.CurrentAnnouncement ) > 0;
            _passedAnnouncesForm.AddMessage( player.Name, GetAnnouncementString( currentAnnounce ), isActive );

            Thread.Sleep( 1000 - Properties.Settings.Default.Speed*50 );

            this.Text = StringResources.lastBid;
            this.Text += GetAnnouncementString( currentAnnounce );
            this.Text += StringResources.saidBy;
            this.Text += player.Name;
        }
Exemplo n.º 17
0
 private void ComputerPlayerPlayed( Player player, Card playedCard )
 {
     SetPlayerActive( null );
     MoveCardToTable( player.Position, playedCard );
 }
        /// <summary>
        /// Stores and announcement made by a player
        /// </summary>
        /// <param name="player"></param>
        /// <param name="announce"></param>
        internal void Add( Player player, Announcement announce )
        {
            if( !IsValid( player, announce ))
                throw new InvalidOperationException( "You cannot bid lower than current" );

            if( (_players.Count != 0)&&( player == (Player)_players[_players.Count - 1] ) )
                throw new InvalidOperationException( "You cannot bid twice" );

            _announces.Add( announce );
            _players.Add( player );

            if( announce.Type != AnnouncementTypeEnum.Pass )
            {
                _lastValidAnnouncement = announce;
                _lastBidder = player;
            }
            else
            {
                //4 successive passes end bidding or 3 passes after a legal bid
                if( _announces.Count > 3 )
                {
                    if( ( ( _announces[_announces.Count-1]).Type == AnnouncementTypeEnum.Pass ) &&
                        ( ( _announces[_announces.Count-2]).Type == AnnouncementTypeEnum.Pass ) &&
                        ( ( _announces[_announces.Count-3]).Type == AnnouncementTypeEnum.Pass ) &&
                        ( _lastBidder != null || (_announces[_announces.Count-4]).Type == AnnouncementTypeEnum.Pass ) )
                    {
                        this._isBiddingFinished = true;
                    }
                }
            }
        }
Exemplo n.º 19
0
 private void GameOver( Player winner1, Player winner2 )
 {
     MessageBox.Show( winner1.Name + StringResources.and + winner2.Name + StringResources.win, StringResources.congratulations, MessageBoxButtons.OK );
     _resultsTable.Rows.Clear();
 }
        private bool IsLastValidBidByTeam( Player player )
        {
            if( _lastBidder == player )
                return true;

            if( _players.Count >= 2 )
            {
                if( _players[_players.Count-2] == _lastBidder )
                    return true;
            }

            return false;
        }
Exemplo n.º 21
0
        private Announcement HumanPlayerIsBidding( Player player, AnnouncementManager manager )
        {
            SetPlayerActive( player );
            _announceForm.Bid( player, manager );
            _announceForm.ShowDialog();
            this.Update();

            Announcement currentAnnounce = _announceForm.Announce;

            this.Text = StringResources.lastBid;
            this.Text += GetAnnouncementString( currentAnnounce );
            this.Text += StringResources.saidBy;
            this.Text += player.Name;

            bool isActive = currentAnnounce.CompareTo( _game.CurrentDeal.CurrentAnnouncement ) > 0;
            _passedAnnouncesForm.AddMessage( player.Name, GetAnnouncementString( currentAnnounce ), isActive );

            return currentAnnounce;
        }
        /// <summary>
        /// If announcement made by this player is valid according to game rules
        /// </summary>
        public bool IsValid( Player player, Announcement announce )
        {
            if( player == null)
                throw new ArgumentNullException( "Player", "Bidding player cannot be null");

            if(	announce == null)
                throw new ArgumentNullException( "Announcement", "Announcement cannot be null");

            return IsValid( player, announce.Type, announce.IsDoubled, announce.IsReDoubled );
        }
Exemplo n.º 23
0
 private void SetPlayerActive( Player player )
 {
     if ( player == null )
     {
         _picPos.Image = Properties.Resources.AllPos;
     }
     else
     {
         switch ( player.Position )
         {
             case PlayerPosition.South:
                 _picPos.Image = Properties.Resources.SouthPos;
                 break;
             case PlayerPosition.East:
                 _picPos.Image = Properties.Resources.EastPos;
                 break;
             case PlayerPosition.North:
                 _picPos.Image = Properties.Resources.NorthPos;
                 break;
             case PlayerPosition.West:
                 _picPos.Image = Properties.Resources.WestPos;
                 break;
         }
     }
 }
Exemplo n.º 24
0
 public void AddCombination( Player player, CardCombination combination )
 {
     _mapCombinationToPlayer.Add( combination, player );
 }
Exemplo n.º 25
0
        internal Player GetTeamPlayer( Player currentPlayer )
        {
            if( currentPlayer == _southPlayer )
                return _northPlayer;
            if( currentPlayer == _eastPlayer )
                return _westPlayer;
            if( currentPlayer == _northPlayer )
                return _southPlayer;
            if( currentPlayer == _westPlayer )
                return _eastPlayer;

            return _southPlayer;
        }
Exemplo n.º 26
0
 public void Bid( Player player, AnnouncementManager manager )
 {
     this._manager = manager;
     this._player = player;
 }
Exemplo n.º 27
0
 /// <summary>
 /// Raises the DealStarted event
 /// </summary>
 protected void RaiseGameCompleted( Player winner1, Player winner2 )
 {
     if( GameCompleted != null )
         {
             GameCompleted( winner1, winner2 );
         }
 }
Exemplo n.º 28
0
        private void BiddingCompleted( Player winner, Announcement finalAnnounce )
        {
            this.Text = StringResources.gameOf;
            this.Text = GetAnnouncementString( finalAnnounce );
            this.Text = StringResources.saidBy;
            this.Text = winner.Name;

            _passedAnnouncesForm.AddSpaces();
        }
Exemplo n.º 29
0
        private void CombinationAnnounced( Player player, CardCombination combination )
        {
            _passedAnnouncesForm.AddMessage( player.Name, GetCombinationString( combination ), false );

            _dealResultForm.AddCombination( player, combination );
        }
Exemplo n.º 30
0
        private void CheckForBelotCombination( Player player, Card playedCard )
        {
            CardsCollection foundCards = new CardsCollection();
            CardColor trumpColor = GetTrumpColor( );

            if( _currentAnnouncement.Type == AnnouncementTypeEnum.AllTrumps )
            {
                if( _currentHand.IsEmpty )
                {
                    CheckBelotForValidColor( player, playedCard, foundCards );
                }
                else
                {
                    if( playedCard.CardColor == GetPlayingColor( _currentHand ) )
                    {
                        CheckBelotForValidColor( player, playedCard, foundCards );
                    }
                }
            }
            else if( _currentAnnouncement.Type != AnnouncementTypeEnum.NoTrumps && playedCard.CardColor == trumpColor )
            {
                CheckBelotForValidColor( player, playedCard, foundCards );
            }

            if( foundCards.Count != 0 )
            {
                BelotFound( player, new BelotCombination( foundCards, 20) );
            }
        }