/// <summary>
 /// Handles the bluetooth messages recived (only <see cref="BTLibrary.PackageBid"/>, <see cref="BTLibrary.PackageSeme"/> and <see cref="BTLibrary.PackageCard"/> packages will be accepted).
 /// </summary>
 /// <param name="pkg">Package.</param>
 private void handleMessage(PackageBase pkg)
 {
     if (pkg == EnPackageType.BID)
     {
         PackageBid pkgb = (PackageBid)pkg;
         if (pkgb.bid.bidder.order == _player && pkgb.nOfBid > Board.Instance.NumberOfBid)
         {
             _readyBid = true;
             //recreate bid from message
             _bid = pkgb.bid;
         }
     }
     else if (pkg == EnPackageType.SEME)
     {
         PackageSeme pkgs = (PackageSeme)pkg;
         if (pkgs.player.order == _player)
         {
             _readySeme = true;
             //recreate bid from message
             _seme = pkgs.seme;
         }
     }
     else if (pkg == EnPackageType.MOVE)
     {
         PackageCard pkgm = (PackageCard)pkg;
         if (pkgm.player.order == _player && pkgm.time >= Board.Instance.Time)
         {
             _readyCard = true;
             //recreate bid from message
             _card = pkgm.card;
         }
     }
 }
Example #2
0
        /// <summary>
        /// Method that returns which bid the AI wants to place in the auction.
        /// </summary>
        /// <returns>The bid.</returns>
        public BidBase ChooseBid()
        {
            BidBase bid = _bidChooser.ChooseABid();

            if (bid == null)
            {
                return(new PassBid(me));
            }

            return(bid);
        }
Example #3
0
        /// <summary>
        /// Sends the BID message to the master (if i'm slave) or to all slaves (if i'm master).
        /// </summary>
        /// <remarks>See <see cref="BTLibrary.PackageBid"/> for further informations about the message contents.</remarks>
        /// <param name="bid">The bid to send.</param>
        private void bidPlaced(BidBase bid)
        {
            //When the Board event eventIPlaceABid or eventSomeonePlaceABid occours, write to master (if i'm slave) or to all slave (if i'm master) the message.

            if (BTManager.Instance.isSlave())
            {
                BTManager.Instance.WriteToMaster(new PackageBid(bid));
            }
            else
            {
                BTManager.Instance.WriteToAllSlave(new PackageBid(bid));
            }
        }
Example #4
0
        public void setup()
        {
            Board.Instance.Reset();

            using (TestRandom rnd = new TestRandom())
                Board.Instance.InitializeMaster(new string[] { "A", "B", "C", "D", "E" }, 2, rnd);                //il mazziere è C

            _null1 = null;
            _null2 = null;

            _pass1 = new PassBid(Board.Instance.AllPlayers [0]);
            _pass2 = new PassBid(Board.Instance.AllPlayers [1]);

            _normalBid1 = new NormalBid(Board.Instance.AllPlayers [0], EnNumbers.ASSE, 70);
            _normalBid2 = new NormalBid(Board.Instance.AllPlayers [1], EnNumbers.DUE, 61);
            _normalBid3 = new NormalBid(Board.Instance.AllPlayers [2], EnNumbers.DUE, 70);
            _normalBid4 = new NormalBid(Board.Instance.AllPlayers [2], EnNumbers.DUE, 70);

            _carichi1 = new CarichiBid(Board.Instance.AllPlayers [0], 61);
            _carichi2 = new CarichiBid(Board.Instance.AllPlayers [0], 70);
            _carichi3 = new CarichiBid(Board.Instance.AllPlayers [0], 70);
        }
Example #5
0
        public BidBase ChooseBid()
        {
            Console.WriteLine("******************************");

            BidBase wb = Board.Instance.currentAuctionWinningBid;

            if (wb == null)
            {
                Console.WriteLine("Non c'è nessuna bid");
            }
            else
            {
                Console.WriteLine("Offerta vincente:" + wb.ToString());
            }

            Console.WriteLine("Devi fare una offerta [passo=p; carichi=c, normale=qualsiasi altra cosa]");

            string a = Console.ReadLine();

            if (a == "p")
            {
                return(new PassBid());
            }
            else if (a == "c")
            {
                Console.Write("Punti: ");
                return(new CarichiBid(int.Parse(Console.ReadLine())));
            }
            else
            {
                Console.Write("Numero[0=due,...,8=tre,9=asse]: ");
                EnNumbers n = (EnNumbers)int.Parse(Console.ReadLine());
                Console.Write("Punti: ");
                int p = int.Parse(Console.ReadLine());
                return(new NormalBid(n, p));
            }
        }
Example #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BTLibrary.PackageBid"/> class.
        /// </summary>
        /// <param name="bs">The byte array representing the bid.</param>
        /// <exception cref="System.Exception">Thrown when the byte sequence doesen't represent a bid.</exception>
        public PackageBid(byte [] bs) : base(EnPackageType.BID)
        {
            if (bs [0] != (byte)type)
            {
                throw new Exception("Wrong byte's sequence");
            }

            Player bidder = (Player)bs [1];

            if (bs [2] == 255)
            {
                bid = new PassBid(bidder);
            }
            else if (bs [3] == 255)
            {
                bid = new CarichiBid(bidder, (int)bs [2]);
            }
            else
            {
                bid = new NormalBid(bidder, (EnNumbers)bs [3], (int)bs [2]);
            }

            nOfBid = (int)bs [4];
        }
Example #7
0
 public static void someonePlaceABid(BidBase bid)
 {
     Console.WriteLine("Nuova bid:" + bid.ToString());
 }
Example #8
0
 /// <summary>
 /// Initializes this instance.
 /// </summary>
 /// <param name="me">The <see cref="ChiamataLibrary.Player"/> instance representing the AI.</param>
 /// <param name="seme">The seme that will be chosen by the AI if it wins the auction.</param>
 public void Setup(Player me, EnSemi seme)
 {
     this._me   = me;
     this._seme = seme;
     _lastBid   = SetLastBid();
 }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BTLibrary.PackageBid"/> class.
 /// </summary>
 /// <param name="bid">The bid that will be inserted in the message.</param>
 public PackageBid(BidBase bid) : base(EnPackageType.BID)
 {
     this.bid = bid;
     nOfBid   = Board.Instance.NumberOfBid;
 }