예제 #1
0
        private void cmdPropose_Click(object sender, EventArgs e)
        {
            long[] gain = list.getTotalGain();

            if (gain[1] > 0)
            {             // accepted
                MessageBox.Show(String.Format(language.getAString(language.order.proposingAccept), Form1.game.playerList[players[1]].playerName), String.Format(language.getAString(language.order.panNegociatingWith), Form1.game.playerList[players[1]].civName));
                list.executeExchange();
                this.Close();
            }
            else
            {
                negoList tempList = aiNego.fillProp(list, 1);
                //	userChoice ui;

                if (tempList != null)
                {
                    list = tempList;
                    populateLBs();
                    MessageBox.Show(
                        String.Format(language.getAString(language.order.proposingRefusesPropose), Form1.game.playerList[players[1]].playerName),
                        String.Format(language.getAString(language.order.panNegociatingWith), Form1.game.playerList[players[1]].civName)
                        );
                }
                else
                {
                    MessageBox.Show(
                        String.Format(language.getAString(language.order.proposingRefusesAll), Form1.game.playerList[players[1]].playerName),
                        String.Format(language.getAString(language.order.panNegociatingWith), Form1.game.playerList[players[1]].civName)
                        );
                }
            }
        }
예제 #2
0
        public negoList getClone()
        {
            /*= (negoList)this.MemberwiseClone();
             * list.*/

            negoList list = new negoList(players);

            list.list = new List[this.list.Length];               //  this.list;
            this.list.CopyTo(list.list, 0);

            list.wiw = new int[this.wiw.Length];
            this.wiw.CopyTo(list.wiw, 0);

            list.canGiveMoney = new long[this.canGiveMoney.Length];              //this.canGiveMoney;
            this.canGiveMoney.CopyTo(list.canGiveMoney, 0);

            list.canGivePerTurn = new long[this.canGivePerTurn.Length];              //this.canGivePerTurn;
            this.canGivePerTurn.CopyTo(list.canGivePerTurn, 0);

            list.giveMoney = new long[this.giveMoney.Length];              //this.giveMoney;
            this.giveMoney.CopyTo(list.giveMoney, 0);

            list.moneyPerTurn = new long[this.moneyPerTurn.Length];              //this.moneyPerTurn;
            this.moneyPerTurn.CopyTo(list.moneyPerTurn, 0);

            return(list);
        }
예제 #3
0
		public static bool acceptToInitNego( negoList nl, int proposer )
		{
			if ( nl.players[ ( proposer + 1 ) % 2 ] == Form1.game.curPlayerInd )
			{
				if( System.Windows.Forms.MessageBox.Show( 
					String.Format( language.getAString( language.order.tradeDoYouWantTo ), Form1.game.playerList[ nl.players[ proposer ] ].playerName ), 
					String.Format( language.getAString( language.order.panNegociatingWith ), Form1.game.playerList[ nl.players[ proposer ] ].civName ),
					System.Windows.Forms.MessageBoxButtons.YesNo,
					System.Windows.Forms.MessageBoxIcon.None,
					System.Windows.Forms.MessageBoxDefaultButton.Button1
					) == System.Windows.Forms.DialogResult.Yes
					)
					return true;
				else
					return false;
			}
			else
			{
				int[] whw = nl.whatHeWants( ( proposer + 1 ) % 2 );
				int totInterestings = 0;

				for ( int i = 0; i < whw.Length; i++ )
					if ( whw[ i ] > 0 )
						totInterestings += whw[ i ];

				if ( totInterestings > 0 )
					return true;
				else
					return false;
			}
		}
예제 #4
0
        public void addExchange(negoList list)
        {
            byte other;

            if (list.players[0] == player.player)
            {
                other = list.players[1];
            }
            else
            {
                other = list.players[0];
            }

            int tot = 0;


            int[] inds0 = new int[100];

            for (int p = 0; p < 2; p++)
            {
                if (list.moneyPerTurn[p] > 0)
                {
                    inds0[tot] = (int)nego.infoType.giveMoneyPerTurn;
                    tot++;
                    inds0[tot] = list.players[p];
                    tot++;
                    inds0[tot] = (int)list.moneyPerTurn[p];
                    tot++;
                }
            }

            for (int i = 0; i < list.Length; i++)
            {
                if (list.list[i].type == (int)nego.infoType.giveResource)
                {
                    inds0[tot] = list.list[i].type;
                    tot++;
                    inds0[tot] = list.players[list.list[i].player];
                    tot++;
                    inds0[tot] = list.list[i].info;
                    tot++;
                }
            }

            if (tot > 0)
            {
                int[] inds1 = new int[tot + 1];
                inds1[0] = other;

                for (int i = 0; i < tot; i++)
                {
                    inds1[i + 1] = inds0[i];
                }

                add((byte)enums.playerMemory.exchangeWith, inds1, player.game.curTurn);
            }
        }
예제 #5
0
		public static void initNego( byte player, byte otherPlayer )
		{
			if ( !Form1.game.playerList[ player ].memory.attemptedNegoRecently( otherPlayer ) )
			{
				int p = 1;
				negoList nl = new negoList( new byte[] { otherPlayer, player } );
				int[] whw = nl.whatHeWants( p );
				int totInterestings = 0, totInterest = 0;

				for ( int i = 0; i < whw.Length; i++ )
					if ( whw[ i ] > 0 )
					{
						totInterestings ++;
						totInterest += whw[ i ];
					}

				if ( totInterestings > 0 )
					for ( int i = 0; i < nl.Length; i++ )
						if ( 
							whw[ i ] > totInterestings * 33 / 100 /*&&
							whw[ i ] < totInterestings * 66 / 100*/
							)
							nl.add( i );

				nl = fillProp( nl, (p+1)%2 );
				if ( nl != null )
				{
					for ( int p1 = 0; p1 < 2; p1 ++ )
						Form1.game.playerList[ nl.players[ p1 ] ].memory.addAttemptedNego( nl.players[ (p1+1)%2 ] );

					if ( acceptToInitNego( nl, p ) )
					{
						if ( otherPlayer == Form1.game.curPlayerInd )
						{
							wC.show = false;
							frmNegociation fn = new frmNegociation( Form1.game.curPlayerInd, player, -1 );

							fn.list = nl;
							fn.populateLBs();
							fn.ShowDialog();
							wC.show = true;
						}
						else
						{
							nl = fillProp( nl, p );
							if ( nl != null )
								nl.executeExchange();
						}
					}
				}
			}
		}
예제 #6
0
        private void cmdDiscuss_Click(object sender, EventArgs e)
        {
            negoList tempList = aiNego.fillProp(list, 1);

            if (tempList != null)
            {
                list = tempList;
            }
            else
            {
                MessageBox.Show(
                    String.Format(language.getAString(language.order.proposingRefusesAll), Form1.game.playerList[players[1]].playerName),
                    String.Format(language.getAString(language.order.panNegociatingWith), Form1.game.playerList[players[1]].civName)
                    );
            }

            populateLBs();
        }
예제 #7
0
        public static bool acceptToInitNego(negoList nl, int proposer)
        {
            if (nl.players[(proposer + 1) % 2] == Form1.game.curPlayerInd)
            {
                if (System.Windows.Forms.MessageBox.Show(
                        String.Format(language.getAString(language.order.tradeDoYouWantTo), Form1.game.playerList[nl.players[proposer]].playerName),
                        String.Format(language.getAString(language.order.panNegociatingWith), Form1.game.playerList[nl.players[proposer]].civName),
                        System.Windows.Forms.MessageBoxButtons.YesNo,
                        System.Windows.Forms.MessageBoxIcon.None,
                        System.Windows.Forms.MessageBoxDefaultButton.Button1
                        ) == System.Windows.Forms.DialogResult.Yes
                    )
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                int[] whw             = nl.whatHeWants((proposer + 1) % 2);
                int   totInterestings = 0;

                for (int i = 0; i < whw.Length; i++)
                {
                    if (whw[i] > 0)
                    {
                        totInterestings += whw[i];
                    }
                }

                if (totInterestings > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
예제 #8
0
        /// <summary>
        /// diff = gain player 1 - gain player 0
        /// </summary>
        /// <returns>gain player 1 - gain player 0, if >0 comp accept</returns>

        /*	public static long[] evaluateOffer( negoList list )
         *      {
         *              //long[] gain = new long[ 2 ];
         *              /*int cityValuePerPop = 50,
         *              cityValuePerBuilding = 20,
         *              contact = 30,
         *              techno = 2,
         *              mapPerCase = 5;
         *
         *              for ( int p = 0; p < 2; p++ )
         *              {
         *                      int wiw = ai.whoIsWinning( players[ p ], players[ ( p + 1 ) % 2 ] ) - 10;
         *
         *                      gain[ p ] += moneyGiven[ p ];
         *
         *                      if ( moneyPerTurn[ p ] > 0 )
         *                              for ( int t = 0; t < 20; t++ )
         *                                      gain[ p ] += (int)( moneyPerTurn[ p ] * ( 100 - 15 * Math.Pow( t, 0.4 ) ) / 100 );
         *
         *                      for ( int i = 0; i < bilateral.Length; i++ )
         *                              if ( usedInBilateral[ i ] )
         *                                      gain[ p ] += getGain( players, bilateral[ i ], p, wiw );
         *
         *                      for ( int i = 0; i < unilateral[ p ].Length; i++ )
         *                              if ( usedInUnilateral[ p ][ i ] )
         *                                      gain[ p ] += getGain( players, unilateral[ p ][ i ], p, wiw );
         *              }
         *
         *              return gain;//gain[ai] - gain[ (ai+1)%2 ];
         *      }*/

        #endregion

        #region getGain

        /*	public static int getGain(byte[] players, structures.intByte ib, int p, int wiw)
         *      {
         *              int gain = 0;
         *              int cityValuePerPop = 50,
         *                      cityValuePerBuilding = 20,
         *                      contact = 30,
         *                      techno = 2,
         *                      mapPerCase = 5;
         *
         *              if ( ib.type == (byte)nego.infoType.breakAllianceWith )
         *              {
         *                      if ( Form1.game.playerList[ players[ p ] ].foreignRelation[ ib.info ].politic == (byte)Form1.relationPolType.alliance || Form1.game.playerList[ players[ p ] ].foreignRelation[ ib.info ].politic == (byte)Form1.relationPolType.Protected || Form1.game.playerList[ players[ p ] ].foreignRelation[ ib.info ].politic == (byte)Form1.relationPolType.Protector )
         *                              gain -= 150; // difficulty
         *                              else if ( Form1.game.playerList[ players[ p ] ].foreignRelation[ ib.info ].politic == (byte)Form1.relationPolType.war )
         *                              gain += 200;
         *                      else
         *                              gain -= 50; // difficulty
         *              }
         *              else if ( ib.type == (byte)nego.infoType.warOn )
         *              {
         *                      if ( Form1.game.playerList[ players[ p ] ].foreignRelation[ ib.info ].politic == (byte)Form1.relationPolType.alliance || Form1.game.playerList[ players[ p ] ].foreignRelation[ ib.info ].politic == (byte)Form1.relationPolType.Protected || Form1.game.playerList[ players[ p ] ].foreignRelation[ ib.info ].politic == (byte)Form1.relationPolType.Protector )
         *                              gain -= 350; // difficulty
         *                              else if ( Form1.game.playerList[ players[ p ] ].foreignRelation[ ib.info ].politic == (byte)Form1.relationPolType.war )
         *                              gain += 300;
         *                      else
         *                              gain -= 200; // difficulty
         *              }
         *              else if ( ib.type == (byte)nego.infoType.embargoOn )
         *              {
         *                      //	int wiw = ai.whoIsWinning( players[ p ], players[ ( p + 1 ) % 2 ] ) * -1 - 10;
         *                      if ( Form1.game.playerList[ players[ p ] ].foreignRelation[ ib.info ].politic == (byte)Form1.relationPolType.alliance || Form1.game.playerList[ players[ p ] ].foreignRelation[ ib.info ].politic == (byte)Form1.relationPolType.Protected || Form1.game.playerList[ players[ p ] ].foreignRelation[ ib.info ].politic == (byte)Form1.relationPolType.Protector )
         *                              gain -= 350; // difficulty
         *                              else if ( Form1.game.playerList[ players[ p ] ].foreignRelation[ ib.info ].politic == (byte)Form1.relationPolType.war )
         *                              gain += 300;
         *                      else
         *                              gain -= 200; // difficulty
         *              }
         *              else if ( ib.type == (byte)nego.infoType.politicTreaty )
         *              {
         *                      if ( ib.info == (byte)Form1.relationPolType.ceaseFire )
         *                              gain += wiw * -40;
         *                      else if ( ib.info == (byte)Form1.relationPolType.peace )
         *                              gain += wiw * -10;
         *                      else if ( ib.info == (byte)Form1.relationPolType.alliance || ib.info == (byte)Form1.relationPolType.Protected || ib.info == (byte)Form1.relationPolType.Protector )
         *                              gain += wiw * -10;
         *              }
         *              else if ( ib.type == (byte)nego.infoType.economicTreaty )
         *              {
         *                      gain += 10;
         *              }
         *              else if ( ib.type == (byte)nego.infoType.votes )
         *              {
         *                      gain += 10;
         *              }
         *              else if ( ib.type == (byte)nego.infoType.giveCity )
         *              {
         *                      gain -= cityValuePerPop * Form1.game.playerList[ players[ p ] ].cityList[ ib.info ].population + cityValuePerBuilding * Form1.game.playerList[ players[ p ] ].cityList[ ib.info ].buildingCount;
         *              }
         *              else if ( ib.type == (byte)nego.infoType.giveContactWith )
         *              {
         *                      gain -= contact;
         *              }
         *              else if ( ib.type == (byte)nego.infoType.giveMap )
         *              {
         *                      if ( ib.info == 0 ) // world map
         *                      {
         *                              int tot = 0;
         *
         *                              for ( int x = 0; x < Form1.game.width; x++ )
         *                                      for ( int y = 0; y < Form1.game.height; y++ )
         *                                              if ( !Form1.game.playerList[ players[ p ] ].discovered[ x, y ] && Form1.game.playerList[ players[ ( p + 1 ) % 2 ] ].discovered[ x, y ] )
         *                                                      tot++;
         *
         *                              gain -= tot * mapPerCase;
         *                      }
         *                      else // territory map
         *                      {
         *                              int tot = 0;
         *
         *                              for ( int x = 0; x < Form1.game.width; x++ )
         *                                      for ( int y = 0; y < Form1.game.height; y++ )
         *                                              if ( !Form1.game.playerList[ players[ p ] ].discovered[ x, y ] && Form1.game.grid[ x, y ].territory - 1 == players[ ( p + 1 ) % 2 ] )
         *                                                      tot++;
         *
         *                              gain -= tot * mapPerCase;
         *                      }
         *              }
         *              else if ( ib.type == (byte)nego.infoType.giveTechno )
         *              {
         *                      gain -= Statistics.technologies[ ib.info ].cost * techno;
         *              }
         *              else if ( ib.type == (byte)nego.infoType.threat )
         *              {
         *                      if ( ib.info == 0 ) // war
         *                              gain += wiw * 50;
         *                      else if ( ib.info == 1 ) // embargo
         *                              gain += wiw * 10; // var with exchanges
         *                              else // alliance
         *                              gain += wiw * 20;
         *              }
         *              else if ( ib.type == (byte)nego.infoType.giveRegion )
         *              {
         *                      for ( int c = 1; c <= Form1.game.playerList[ players[ p ] ].cityNumber; c++ )
         *                              if ( Form1.game.playerList[ players[ p ] ].cityList[ c ].state != (byte)enums.cityState.dead && Form1.game.playerList[ players[ p ] ].cityList[ c ].originalOwner == ib.info )
         *                                      gain -= cityValuePerPop * Form1.game.playerList[ players[ p ] ].cityList[ ib.info ].population + cityValuePerBuilding * Form1.game.playerList[ players[ p ] ].cityList[ ib.info ].buildingCount;
         *              }
         *
         *              return gain;
         *      }*/

        #endregion

        #region fillProp
        /// <summary>
        ///
        /// </summary>
        /// <param name="p">ai pos who evaluates</param>
        /// <returns></returns>
        public static negoList fillProp(negoList list, int p)
        {
            /*		negoList oriList = /*new negoList( list.players );
             *              oriList =* list.getClone();			*/

            negoList tempList = list.getClone();

            long[] gain = tempList.getTotalGain();
            int[]  whw  = tempList.whatHeWants(p);

            while (gain[p] < 0)
            {
                long[] possibilities = new long[tempList.Length];
                bool[] valid         = new bool[tempList.Length];

                for (int i = 0; i < tempList.Length; i++)
                {
                    if (!tempList.list[i].accepted)
                    {
                        long[] pg = tempList.getPossibleGain(i);
                        if (
                            pg[p] > 0 &&
                            pg[(p + 1) % 2] + gain[(p + 1) % 2] > 0
                            )
                        {
                            possibilities[i] = whw[i] * 300 + pg[p];                                   //pg[ p ] - pg[ ( p + 1 ) % 2 ];
                            valid[i]         = true;
                        }
                    }
                }

                int[] order = count.descOrder(possibilities);
                if (valid[order[0]])
                {
                    long[] pg = tempList.getPossibleGain(order[0]);

                    for (int k = 0; k < 2; k++)
                    {
                        gain[k] += pg[k];
                    }

                    tempList.add(order[0]);
                }
                else
                {
                    break;
                }
            }

            if (tempList.giveMoney[p] == 0)
            {
                while (
                    gain[p] < 0 &&
                    tempList.giveMoney[(p + 1) % 2] < tempList.canGiveMoney[(p + 1) % 2]
                    )
                {
                    gain[p]           += 1;
                    gain[(p + 1) % 2] -= 1;
                    tempList.addToGiveMoney((p + 1) % 2, 1);
                }

                while (
                    gain[p] < 0 &&
                    tempList.moneyPerTurn[(p + 1) % 2] < tempList.canGivePerTurn[(p + 1) % 2]
                    )
                {
                    gain[p]           += tempList.getValuePerTurn(1);
                    gain[(p + 1) % 2] -= tempList.getValuePerTurn(1);
                    tempList.addToMoneyPerTurn((p + 1) % 2, 1);
                }
            }

            if (gain[p] > 0)
            {
                return(tempList);
            }
            else
            {
                return(null);
            }
        }
예제 #9
0
        public static void initNego(byte player, byte otherPlayer)
        {
            if (!Form1.game.playerList[player].memory.attemptedNegoRecently(otherPlayer))
            {
                int      p = 1;
                negoList nl = new negoList(new byte[] { otherPlayer, player });
                int[]    whw = nl.whatHeWants(p);
                int      totInterestings = 0, totInterest = 0;

                for (int i = 0; i < whw.Length; i++)
                {
                    if (whw[i] > 0)
                    {
                        totInterestings++;
                        totInterest += whw[i];
                    }
                }

                if (totInterestings > 0)
                {
                    for (int i = 0; i < nl.Length; i++)
                    {
                        if (
                            whw[i] > totInterestings * 33 / 100                               /*&&
                                                                                               * whw[ i ] < totInterestings * 66 / 100*/
                            )
                        {
                            nl.add(i);
                        }
                    }
                }

                nl = fillProp(nl, (p + 1) % 2);
                if (nl != null)
                {
                    for (int p1 = 0; p1 < 2; p1++)
                    {
                        Form1.game.playerList[nl.players[p1]].memory.addAttemptedNego(nl.players[(p1 + 1) % 2]);
                    }

                    if (acceptToInitNego(nl, p))
                    {
                        if (otherPlayer == Form1.game.curPlayerInd)
                        {
                            wC.show = false;
                            frmNegociation fn = new frmNegociation(Form1.game.curPlayerInd, player, -1);

                            fn.list = nl;
                            fn.populateLBs();
                            fn.ShowDialog();
                            wC.show = true;
                        }
                        else
                        {
                            nl = fillProp(nl, p);
                            if (nl != null)
                            {
                                nl.executeExchange();
                            }
                        }
                    }
                }
            }
        }
예제 #10
0
		public negoList getClone()
		{ 
			/*= (negoList)this.MemberwiseClone();
			list.*/

			negoList list = new negoList( players );

			list.list = new List[ this.list.Length ]; //  this.list;
			this.list.CopyTo( list.list, 0 );

			list.wiw = new int[ this.wiw.Length ];
			this.wiw.CopyTo( list.wiw, 0 );

			list.canGiveMoney = new long[ this.canGiveMoney.Length ];//this.canGiveMoney;
			this.canGiveMoney.CopyTo( list.canGiveMoney, 0 );

			list.canGivePerTurn = new long[ this.canGivePerTurn.Length ];//this.canGivePerTurn;
			this.canGivePerTurn.CopyTo( list.canGivePerTurn, 0 );

			list.giveMoney = new long[ this.giveMoney.Length ];//this.giveMoney;
			this.giveMoney.CopyTo( list.giveMoney, 0 );

			list.moneyPerTurn = new long[ this.moneyPerTurn.Length ];//this.moneyPerTurn;
			this.moneyPerTurn.CopyTo( list.moneyPerTurn, 0 );

			return list;
		}
예제 #11
0
		public void addExchange( negoList list )
		{
			byte other;
			if ( list.players[ 0 ] == player.player )
				other = list.players[ 1 ];
			else
				other = list.players[ 0 ];

			int tot = 0;


			int[] inds0 = new int[ 100 ];

			for ( int p = 0; p < 2; p ++ )
				if ( list.moneyPerTurn[ p ] > 0 )
				{
					inds0[ tot ] = (int)nego.infoType.giveMoneyPerTurn;
					tot++;
					inds0[ tot ] = list.players[ p ];
					tot++;
					inds0[ tot ] = (int)list.moneyPerTurn[ p ];
					tot++;
				}

			for ( int i = 0; i < list.Length; i++ )
			{
				if ( list.list[ i ].type == (int)nego.infoType.giveResource )
				{
					inds0[ tot ] = list.list[ i ].type;
					tot++;
					inds0[ tot ] = list.players[ list.list[ i ].player ];
					tot++;
					inds0[ tot ] = list.list[ i ].info;
					tot++;
				}
			}

			if ( tot > 0 )
			{
				int[] inds1 = new int[ tot + 1 ];
				inds1[ 0 ] = other;

				for ( int i = 0; i < tot; i ++ )
					inds1[ i + 1 ] = inds0[ i ];

				add( (byte)enums.playerMemory.exchangeWith, inds1, player.game.curTurn );
			}
		}
예제 #12
0
		private void cmdPropose_Click(object sender, EventArgs e)
		{
			long[] gain = list.getTotalGain();

			if ( gain[ 1 ] > 0 )
			{ // accepted
				MessageBox.Show( String.Format( language.getAString( language.order.proposingAccept ), Form1.game.playerList[ players[ 1 ] ].playerName ), String.Format( language.getAString( language.order.panNegociatingWith ), Form1.game.playerList[  players[ 1 ] ].civName ) );
				list.executeExchange();
				this.Close();
			}
			else
			{
				negoList tempList = aiNego.fillProp( list, 1 );
			//	userChoice ui;

				if ( tempList != null )
				{
					list = tempList;
					populateLBs();
					MessageBox.Show(
						String.Format( language.getAString( language.order.proposingRefusesPropose ), Form1.game.playerList[ players[ 1 ] ].playerName ), 
						String.Format( language.getAString( language.order.panNegociatingWith ), Form1.game.playerList[ players[ 1 ] ].civName ) 
						);
				}
				else
				{
					MessageBox.Show(
						String.Format( language.getAString( language.order.proposingRefusesAll ), Form1.game.playerList[ players[ 1 ] ].playerName ), 
						String.Format( language.getAString( language.order.panNegociatingWith ), Form1.game.playerList[ players[ 1 ] ].civName ) 
						);
				}
			}
		}
예제 #13
0
		private void cmdDiscuss_Click(object sender, EventArgs e)
		{
			negoList tempList = aiNego.fillProp( list, 1 );

			if ( tempList != null )
				list = tempList;
			else
				MessageBox.Show( 
					String.Format( language.getAString( language.order.proposingRefusesAll ), Form1.game.playerList[ players[ 1 ] ].playerName ), 
					String.Format( language.getAString( language.order.panNegociatingWith ), Form1.game.playerList[  players[ 1 ] ].civName ) 
					);

			populateLBs();
		}
예제 #14
0
		public frmNegociation( byte player, byte other, sbyte voteFor )
		{
			//
			// Required for Windows Form Designer support
			//
			lb = new System.Windows.Forms.ListBox[ 2 ];
			InitializeComponent();
			//
			// TODO: Add any constructor code after InitializeComponent call
			//
			this.cmdPropose.Text = language.getAString( language.order.Propose );
			this.cmdRefuse.Text = language.getAString( language.order.Refuse );
			this.cmdDiscuss.Text = language.getAString( language.order.Discuss );
			this.cmdAdd.Text = language.getAString( language.order.Add );
			this.cmdRemove.Text = language.getAString( language.order.Remove );

			players = new byte[ 2 ];
			players[ 0 ] = player;
			players[ 1 ] = other;

			list = new negoList( players );

			cmdRefuse.Left = space;
			cmdRefuse.Top = this.Height - cmdRefuse.Height - space;
			cmdRefuse.Width = ( this.Width - 4 * space ) / 3;

			cmdDiscuss.Left = cmdRefuse.Right + space;
			cmdDiscuss.Top = this.Height - cmdRefuse.Height - space;
			cmdDiscuss.Width = ( this.Width - 4 * space ) / 3;

			cmdPropose.Enabled = false;
			cmdPropose.Left = cmdDiscuss.Right + space;
			cmdPropose.Top = this.Height - cmdRefuse.Height - space;
			cmdPropose.Width = ( this.Width - 4 * space ) / 3;

			cmdAdd.Width = ( this.Width - 4 * space ) / 3;
			cmdAdd.Left = (this.Width - cmdAdd.Width * 2)/3;
			cmdAdd.Top = cmdRefuse.Top - space - cmdAdd.Height;

			cmdRemove.Enabled = false;
			cmdRemove.Width = ( this.Width - 4 * space ) / 3;
			cmdRemove.Left = cmdAdd.Right + ( this.Width - cmdAdd.Width * 2 ) / 3;
			cmdRemove.Top = cmdRefuse.Top - space - cmdAdd.Height;

			lb[ 0 ].Left = space;
			lb[ 0 ].Width = (this.Width - 3 * space)/2;
			lb[ 0 ].Top = cmdAdd.Top - space - lb[ 0 ].Height;

			lb[ 1 ].Left = lb[ 0 ].Right + space;
			lb[ 1 ].Width = (this.Width - 3 * space)/2;
			lb[ 1 ].Top = cmdAdd.Top - space - lb[ 1 ].Height;

			lbContent = new int[ 2 ][ ];
			for ( int i = 0; i < players.Length; i++ )
				lbContent[ i ] = new int[ 100 ];

	#region init var

		/*	negos.treaties = new bool[ (byte)Form1.relationPolType.totp1 ];
			negos.threats = new bool[ 3 ];
			negos.playerGive = new structures.negoGive[ 2 ];
			lbContent = new structures.intByte[ 2 ][ ];
			for ( int i = 0; i < players.Length; i++ )
			{
				negos.playerGive[ i ].moneyLeft = Form1.game.playerList[ players[ i ] ].money;
				negos.playerGive[ i ].moneyGive = 0;
				negos.playerGive[ i ].technoGive = new bool[ Statistics.technologies.Length ];
				negos.playerGive[ i ].cityGive = new bool[ Form1.game.playerList[ players[ i ] ].cityNumber + 1 ];
				negos.playerGive[ i ].regionGive = new bool[ Form1.game.playerList.Length ];
				negos.playerGive[ i ].contactGive = new bool[ Form1.game.playerList.Length ];

				lbContent[ i ] = new structures.intByte[ 0 ];
			}

			byte winningWarByte = ai.whoIsWinning( players[ 0 ], players[ 1 ] );
			bool winningWarBool;

			if ( winningWarByte > 10 )
				winningWarBool = true;
			else
				winningWarBool = false;*/
	#endregion
			
			platformSpec.resolution.set( this.Controls );

			cmdRemove.Enabled = false;
			drawTop();
			populateLBs();
			enableWHTB();
		}
예제 #15
0
		/// <summary>
		/// diff = gain player 1 - gain player 0
		/// </summary>
		/// <returns>gain player 1 - gain player 0, if >0 comp accept</returns>
	/*	public static long[] evaluateOffer( negoList list )
		{
			//long[] gain = new long[ 2 ];
			/*int cityValuePerPop = 50,
			cityValuePerBuilding = 20,
			contact = 30,
			techno = 2,
			mapPerCase = 5;

			for ( int p = 0; p < 2; p++ )
			{
				int wiw = ai.whoIsWinning( players[ p ], players[ ( p + 1 ) % 2 ] ) - 10;

				gain[ p ] += moneyGiven[ p ];

				if ( moneyPerTurn[ p ] > 0 )
					for ( int t = 0; t < 20; t++ )
						gain[ p ] += (int)( moneyPerTurn[ p ] * ( 100 - 15 * Math.Pow( t, 0.4 ) ) / 100 );

				for ( int i = 0; i < bilateral.Length; i++ )
					if ( usedInBilateral[ i ] )
						gain[ p ] += getGain( players, bilateral[ i ], p, wiw );

				for ( int i = 0; i < unilateral[ p ].Length; i++ )
					if ( usedInUnilateral[ p ][ i ] )
						gain[ p ] += getGain( players, unilateral[ p ][ i ], p, wiw );
			}

			return gain;//gain[ai] - gain[ (ai+1)%2 ];
		}*/

#endregion

#region getGain
	/*	public static int getGain(byte[] players, structures.intByte ib, int p, int wiw)
		{
			int gain = 0;
			int cityValuePerPop = 50,
				cityValuePerBuilding = 20,
				contact = 30,
				techno = 2,
				mapPerCase = 5;

			if ( ib.type == (byte)nego.infoType.breakAllianceWith )
			{
				if ( Form1.game.playerList[ players[ p ] ].foreignRelation[ ib.info ].politic == (byte)Form1.relationPolType.alliance || Form1.game.playerList[ players[ p ] ].foreignRelation[ ib.info ].politic == (byte)Form1.relationPolType.Protected || Form1.game.playerList[ players[ p ] ].foreignRelation[ ib.info ].politic == (byte)Form1.relationPolType.Protector )
					gain -= 150; // difficulty
					else if ( Form1.game.playerList[ players[ p ] ].foreignRelation[ ib.info ].politic == (byte)Form1.relationPolType.war )
					gain += 200;
				else
					gain -= 50; // difficulty
			}
			else if ( ib.type == (byte)nego.infoType.warOn )
			{
				if ( Form1.game.playerList[ players[ p ] ].foreignRelation[ ib.info ].politic == (byte)Form1.relationPolType.alliance || Form1.game.playerList[ players[ p ] ].foreignRelation[ ib.info ].politic == (byte)Form1.relationPolType.Protected || Form1.game.playerList[ players[ p ] ].foreignRelation[ ib.info ].politic == (byte)Form1.relationPolType.Protector )
					gain -= 350; // difficulty
					else if ( Form1.game.playerList[ players[ p ] ].foreignRelation[ ib.info ].politic == (byte)Form1.relationPolType.war )
					gain += 300;
				else
					gain -= 200; // difficulty
			}
			else if ( ib.type == (byte)nego.infoType.embargoOn )
			{
				//	int wiw = ai.whoIsWinning( players[ p ], players[ ( p + 1 ) % 2 ] ) * -1 - 10;
				if ( Form1.game.playerList[ players[ p ] ].foreignRelation[ ib.info ].politic == (byte)Form1.relationPolType.alliance || Form1.game.playerList[ players[ p ] ].foreignRelation[ ib.info ].politic == (byte)Form1.relationPolType.Protected || Form1.game.playerList[ players[ p ] ].foreignRelation[ ib.info ].politic == (byte)Form1.relationPolType.Protector )
					gain -= 350; // difficulty
					else if ( Form1.game.playerList[ players[ p ] ].foreignRelation[ ib.info ].politic == (byte)Form1.relationPolType.war )
					gain += 300;
				else
					gain -= 200; // difficulty
			}
			else if ( ib.type == (byte)nego.infoType.politicTreaty )
			{
				if ( ib.info == (byte)Form1.relationPolType.ceaseFire )
					gain += wiw * -40;
				else if ( ib.info == (byte)Form1.relationPolType.peace )
					gain += wiw * -10;
				else if ( ib.info == (byte)Form1.relationPolType.alliance || ib.info == (byte)Form1.relationPolType.Protected || ib.info == (byte)Form1.relationPolType.Protector )
					gain += wiw * -10;
			}
			else if ( ib.type == (byte)nego.infoType.economicTreaty )
			{
				gain += 10;
			}
			else if ( ib.type == (byte)nego.infoType.votes )
			{
				gain += 10;
			}
			else if ( ib.type == (byte)nego.infoType.giveCity )
			{
				gain -= cityValuePerPop * Form1.game.playerList[ players[ p ] ].cityList[ ib.info ].population + cityValuePerBuilding * Form1.game.playerList[ players[ p ] ].cityList[ ib.info ].buildingCount;
			}
			else if ( ib.type == (byte)nego.infoType.giveContactWith )
			{
				gain -= contact;
			}
			else if ( ib.type == (byte)nego.infoType.giveMap )
			{
				if ( ib.info == 0 ) // world map
				{
					int tot = 0;

					for ( int x = 0; x < Form1.game.width; x++ )
						for ( int y = 0; y < Form1.game.height; y++ )
							if ( !Form1.game.playerList[ players[ p ] ].discovered[ x, y ] && Form1.game.playerList[ players[ ( p + 1 ) % 2 ] ].discovered[ x, y ] )
								tot++;

					gain -= tot * mapPerCase;
				}
				else // territory map
				{
					int tot = 0;

					for ( int x = 0; x < Form1.game.width; x++ )
						for ( int y = 0; y < Form1.game.height; y++ )
							if ( !Form1.game.playerList[ players[ p ] ].discovered[ x, y ] && Form1.game.grid[ x, y ].territory - 1 == players[ ( p + 1 ) % 2 ] )
								tot++;

					gain -= tot * mapPerCase;
				}
			}
			else if ( ib.type == (byte)nego.infoType.giveTechno )
			{
				gain -= Statistics.technologies[ ib.info ].cost * techno;
			}
			else if ( ib.type == (byte)nego.infoType.threat )
			{
				if ( ib.info == 0 ) // war
					gain += wiw * 50;
				else if ( ib.info == 1 ) // embargo
					gain += wiw * 10; // var with exchanges
					else // alliance
					gain += wiw * 20;
			}
			else if ( ib.type == (byte)nego.infoType.giveRegion )
			{
				for ( int c = 1; c <= Form1.game.playerList[ players[ p ] ].cityNumber; c++ )
					if ( Form1.game.playerList[ players[ p ] ].cityList[ c ].state != (byte)enums.cityState.dead && Form1.game.playerList[ players[ p ] ].cityList[ c ].originalOwner == ib.info )
						gain -= cityValuePerPop * Form1.game.playerList[ players[ p ] ].cityList[ ib.info ].population + cityValuePerBuilding * Form1.game.playerList[ players[ p ] ].cityList[ ib.info ].buildingCount;
			}

			return gain;
		}*/
			
#endregion

#region fillProp
		/// <summary>
		/// 
		/// </summary>
		/// <param name="p">ai pos who evaluates</param>
		/// <returns></returns>
		public static negoList fillProp( negoList list, int p )
		{

	/*		negoList oriList = /*new negoList( list.players );
			oriList =* list.getClone();			*/						

			negoList tempList = list.getClone();

			long[] gain = tempList.getTotalGain();
			int[] whw = tempList.whatHeWants( p );

			while ( gain[ p ] < 0 )
			{
				long[] possibilities = new long[ tempList.Length ];
				bool[] valid = new bool[ tempList.Length ];

				for ( int i = 0; i < tempList.Length; i ++ ) 
					if ( !tempList.list[ i ].accepted ) 
					{ 
						long[] pg = tempList.getPossibleGain( i ); 
						if ( 
							pg[ p ] > 0 && 
							pg[ (p+1)%2 ] + gain[ (p+1)%2 ] > 0 
							)
						{
							possibilities[ i ] = whw[ i ] * 300 + pg[ p ]; //pg[ p ] - pg[ ( p + 1 ) % 2 ];
							valid[ i ] = true;
						}
					} 

				int[] order = count.descOrder( possibilities );
				if ( valid[ order[ 0 ] ] )
				{
					long[] pg = tempList.getPossibleGain( order[ 0 ] ); 

					for ( int k = 0; k < 2; k ++ )
						gain[ k ] += pg[ k ];

					tempList.add( order[ 0 ] );
				}
				else
				{
					break;
				}
			}

			if ( tempList.giveMoney[ p ] == 0 )
			{
				while ( 
					gain[ p ] < 0 && 
					tempList.giveMoney[ ( p + 1 ) % 2 ] < tempList.canGiveMoney[ ( p + 1 ) % 2 ]
					)
				{
					gain[ p ] += 1;
					gain[ ( p + 1 ) % 2 ] -= 1;
					tempList.addToGiveMoney( ( p + 1 ) % 2, 1 );
				}

				while ( 
					gain[ p ] < 0 && 
					tempList.moneyPerTurn[ ( p + 1 ) % 2 ] < tempList.canGivePerTurn[ ( p + 1 ) % 2 ] 
					)
				{
					gain[ p ] += tempList.getValuePerTurn( 1 );
					gain[ ( p + 1 ) % 2 ] -= tempList.getValuePerTurn( 1 );
					tempList.addToMoneyPerTurn( ( p + 1 ) % 2, 1 );
				}
			}

			if ( gain[ p ] > 0 )
				return tempList;
			else
				return null;
		}
예제 #16
0
        public frmNegociation(byte player, byte other, sbyte voteFor)
        {
            //
            // Required for Windows Form Designer support
            //
            lb = new System.Windows.Forms.ListBox[2];
            InitializeComponent();
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            this.cmdPropose.Text = language.getAString(language.order.Propose);
            this.cmdRefuse.Text  = language.getAString(language.order.Refuse);
            this.cmdDiscuss.Text = language.getAString(language.order.Discuss);
            this.cmdAdd.Text     = language.getAString(language.order.Add);
            this.cmdRemove.Text  = language.getAString(language.order.Remove);

            players    = new byte[2];
            players[0] = player;
            players[1] = other;

            list = new negoList(players);

            cmdRefuse.Left  = space;
            cmdRefuse.Top   = this.Height - cmdRefuse.Height - space;
            cmdRefuse.Width = (this.Width - 4 * space) / 3;

            cmdDiscuss.Left  = cmdRefuse.Right + space;
            cmdDiscuss.Top   = this.Height - cmdRefuse.Height - space;
            cmdDiscuss.Width = (this.Width - 4 * space) / 3;

            cmdPropose.Enabled = false;
            cmdPropose.Left    = cmdDiscuss.Right + space;
            cmdPropose.Top     = this.Height - cmdRefuse.Height - space;
            cmdPropose.Width   = (this.Width - 4 * space) / 3;

            cmdAdd.Width = (this.Width - 4 * space) / 3;
            cmdAdd.Left  = (this.Width - cmdAdd.Width * 2) / 3;
            cmdAdd.Top   = cmdRefuse.Top - space - cmdAdd.Height;

            cmdRemove.Enabled = false;
            cmdRemove.Width   = (this.Width - 4 * space) / 3;
            cmdRemove.Left    = cmdAdd.Right + (this.Width - cmdAdd.Width * 2) / 3;
            cmdRemove.Top     = cmdRefuse.Top - space - cmdAdd.Height;

            lb[0].Left  = space;
            lb[0].Width = (this.Width - 3 * space) / 2;
            lb[0].Top   = cmdAdd.Top - space - lb[0].Height;

            lb[1].Left  = lb[0].Right + space;
            lb[1].Width = (this.Width - 3 * space) / 2;
            lb[1].Top   = cmdAdd.Top - space - lb[1].Height;

            lbContent = new int[2][];
            for (int i = 0; i < players.Length; i++)
            {
                lbContent[i] = new int[100];
            }

            #region init var

            /*	negos.treaties = new bool[ (byte)Form1.relationPolType.totp1 ];
             *      negos.threats = new bool[ 3 ];
             *      negos.playerGive = new structures.negoGive[ 2 ];
             *      lbContent = new structures.intByte[ 2 ][ ];
             *      for ( int i = 0; i < players.Length; i++ )
             *      {
             *              negos.playerGive[ i ].moneyLeft = Form1.game.playerList[ players[ i ] ].money;
             *              negos.playerGive[ i ].moneyGive = 0;
             *              negos.playerGive[ i ].technoGive = new bool[ Statistics.technologies.Length ];
             *              negos.playerGive[ i ].cityGive = new bool[ Form1.game.playerList[ players[ i ] ].cityNumber + 1 ];
             *              negos.playerGive[ i ].regionGive = new bool[ Form1.game.playerList.Length ];
             *              negos.playerGive[ i ].contactGive = new bool[ Form1.game.playerList.Length ];
             *
             *              lbContent[ i ] = new structures.intByte[ 0 ];
             *      }
             *
             *      byte winningWarByte = ai.whoIsWinning( players[ 0 ], players[ 1 ] );
             *      bool winningWarBool;
             *
             *      if ( winningWarByte > 10 )
             *              winningWarBool = true;
             *      else
             *              winningWarBool = false;*/
            #endregion

            platformSpec.resolution.set(this.Controls);

            cmdRemove.Enabled = false;
            drawTop();
            populateLBs();
            enableWHTB();
        }
예제 #17
0
        public popAddNegociation(byte[] Players, negoList List)
        {
            platformSpec.setFloatingWindow.before(this);
            list = List;

            foreach (byte p in list.players)
            {
                if (p != Form1.game.curPlayerInd)
                {
                    this.Text = String.Format(language.getAString(language.order.panNegociatingWith), Form1.game.playerList[p].civName);
                    break;
                }
            }

            int space = 8;

            this.ControlBox = false;

            this.Width  = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width * 9 / 10;
            this.Height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height * 4 / 5;

            cmdOk       = new Button();
            cmdOk.Width = (this.Width - space * 3) / 2;
            cmdOk.Left  = space;
            //	cmdOk.Top = this.Height - space - cmdOk.Height;
            cmdOk.Click  += new EventHandler(cmdOk_Click);
            cmdOk.Text    = language.getAString(language.order.ok);
            cmdOk.Enabled = false;
#if !CF
            cmdOk.FlatStyle = FlatStyle.System;
#endif
            this.Controls.Add(cmdOk);

            cmdCancel       = new Button();
            cmdCancel.Width = (this.Width - space * 3) / 2;
            cmdCancel.Left  = cmdOk.Right + space;
            //	cmdCancel.Top = this.Height - space - cmdOk.Height;
            cmdCancel.Click += new EventHandler(cmdCancel_Click);
            cmdCancel.Text   = language.getAString(language.order.cancel);
#if !CF
            cmdCancel.FlatStyle = FlatStyle.System;
#endif
            this.Controls.Add(cmdCancel);

            tv       = new TreeView();
            tv.Top   = space;
            tv.Left  = space;
            tv.Width = this.Width - space * 2;
            //	tv.Height = cmdOk.Top - space * 2;
            tv.AfterSelect += new TreeViewEventHandler(tv_AfterSelect);
            this.Controls.Add(tv);

            platformSpec.setFloatingWindow.after(this);

            #region floating

/*
 *                      // Mémorise la zone cliente avant le changement de style
 *                      Size aireAvant = this.ClientSize;
 *
 *                      // Récupèrer le handle de la fenêtre
 *                      IntPtr hWnd = Win32Window.FromControl( this );
 *
 *                      // Liste des styles à enlever (voir article)
 *                      int enleves = (int)( Win32Window.WindowStyle.WS_SYSMENU | Win32Window.WindowStyle.WS_MINIMIZEBOX | Win32Window.WindowStyle.WS_MAXIMIZEBOX );
 *
 *                      // Liste des styles à ajouter
 *                      int ajoutes = (int)( Win32Window.WindowStyle.WS_CAPTION | Win32Window.WindowStyle.WS_POPUP );
 *
 *                      // Mise à jour du style de la fenêtre
 *                      Win32Window.UpdateWindowStyle( hWnd, enleves, ajoutes );
 *
 *                      // Mesure l'aide cliente après le changement de style
 *                      Size aireApres = this.ClientSize;
 *
 *                      // Restitue la taille de l'aire cliente
 *                      aireApres.Width += aireAvant.Width - aireApres.Width;
 *                      aireApres.Height += aireAvant.Height - aireApres.Height;
 *                      this.ClientSize = aireApres;
 *                      this.Left = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width / 2 - this.Width / 2;
 *                      this.Top = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height / 2 - this.Height / 2;
 */
            #endregion

            platformSpec.manageWindows.setDialogSize(this);

            this.Top += this.Height / 10;

            cmdOk.Top     = this.ClientSize.Height - space - cmdOk.Height;
            cmdCancel.Top = this.ClientSize.Height - space - cmdOk.Height;
            tv.Height     = cmdOk.Top - space * 2;

            platformSpec.resolution.set(this.Controls);

            list = List;
            populateTree();
        }
예제 #18
0
		public popAddNegociation( byte[] Players, negoList List )
		{
			platformSpec.setFloatingWindow.before( this );
			list = List; 

			foreach ( byte p in list.players )
				if ( p != Form1.game.curPlayerInd )
				{
					this.Text = String.Format( language.getAString( language.order.panNegociatingWith ), Form1.game.playerList[ p ].civName );
					break;
				}

			int space = 8;
			this.ControlBox = false; 

			this.Width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width * 9 / 10;
			this.Height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height * 4 / 5;

			cmdOk = new Button();
			cmdOk.Width = ( this.Width - space * 3 ) / 2;
			cmdOk.Left = space;
		//	cmdOk.Top = this.Height - space - cmdOk.Height;
			cmdOk.Click += new EventHandler(cmdOk_Click);
			cmdOk.Text = language.getAString( language.order.ok );
			cmdOk.Enabled = false;
#if !CF
			cmdOk.FlatStyle = FlatStyle.System;
#endif
			this.Controls.Add( cmdOk );

			cmdCancel = new Button();
			cmdCancel.Width = ( this.Width - space * 3 ) / 2;
			cmdCancel.Left = cmdOk.Right + space;
		//	cmdCancel.Top = this.Height - space - cmdOk.Height;
			cmdCancel.Click += new EventHandler( cmdCancel_Click );
			cmdCancel.Text = language.getAString( language.order.cancel );
#if !CF
			cmdCancel.FlatStyle = FlatStyle.System;
#endif
			this.Controls.Add( cmdCancel );

			tv = new TreeView();
			tv.Top = space;
			tv.Left = space;
			tv.Width = this.Width - space * 2;
		//	tv.Height = cmdOk.Top - space * 2;
			tv.AfterSelect += new TreeViewEventHandler( tv_AfterSelect );
			this.Controls.Add( tv );

			platformSpec.setFloatingWindow.after( this );

			#region floating
/*
			// Mémorise la zone cliente avant le changement de style
			Size aireAvant = this.ClientSize;

			// Récupèrer le handle de la fenêtre
			IntPtr hWnd = Win32Window.FromControl( this );

			// Liste des styles à enlever (voir article)
			int enleves = (int)( Win32Window.WindowStyle.WS_SYSMENU | Win32Window.WindowStyle.WS_MINIMIZEBOX | Win32Window.WindowStyle.WS_MAXIMIZEBOX );

			// Liste des styles à ajouter
			int ajoutes = (int)( Win32Window.WindowStyle.WS_CAPTION | Win32Window.WindowStyle.WS_POPUP );

			// Mise à jour du style de la fenêtre
			Win32Window.UpdateWindowStyle( hWnd, enleves, ajoutes );

			// Mesure l'aide cliente après le changement de style
			Size aireApres = this.ClientSize;

			// Restitue la taille de l'aire cliente
			aireApres.Width += aireAvant.Width - aireApres.Width;
			aireApres.Height += aireAvant.Height - aireApres.Height;
			this.ClientSize = aireApres;
			this.Left = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width / 2 - this.Width / 2;
			this.Top = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height / 2 - this.Height / 2;
			*/
			#endregion

			platformSpec.manageWindows.setDialogSize( this );

			this.Top += this.Height / 10;

			cmdOk.Top = this.ClientSize.Height - space - cmdOk.Height;
			cmdCancel.Top = this.ClientSize.Height - space - cmdOk.Height;
			tv.Height = cmdOk.Top - space * 2;

			platformSpec.resolution.set( this.Controls );

			list = List;
			populateTree();
		}