private void cmdAdd_Click(object sender, EventArgs e) { popAddNegociation pan = new popAddNegociation(players, list); pan.ShowDialog(); if (pan.accepted) { if (pan.result == -1) { list.addToGiveMoney(pan.resultPlayer, pan.resultInd); //list.giveMoney[ pan.resultPlayer ] += pan.resultInd; } else if (pan.result == -2) { list.addToMoneyPerTurn(pan.resultPlayer, pan.resultInd); //list.moneyPerTurn[ pan.resultPlayer ] += pan.resultInd; } else { list.add(pan.result); } populateLBs(); enableWHTB(); } }
/// <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); } }