java - Solving a simple maximization game -


i've got simple question game created (this not homework): should following method contain maximize payoff:

private static boolean goforbiggerresource() {     return ... // must fill }; 

once again stress not homework: i'm trying understand @ work here.

the "strategy" trivial: there can 2 choices: true or false.

the "game" simple:

p1  r1        r2 p2             r5   p3  r3        r4 p4 
  • there 4 players (p1, p2, p3 , p4) , 5 resources (r1, r2, r3, r4 worth 1 , r5, worth 2)

  • each player has 2 options: either go resource close starting location gives 1 , player sure (no other player can resource first) or player can try go resource worth 2... other players may go too.

  • if 2 or more players go bigger resource (the 1 worth 2), they'll arrive @ bigger resource @ same time , 1 player, @ random, , other player(s) going resource 0 (they cannot go resource worth 1).

  • each player play same strategy (the 1 defined in method goforbiggerresource())

  • players cannot "talk" each other agree on strategy

  • the game run 1 million times

so want fill method goforbiggerresource(), returns either true or false, in way maximize payoff.

here's code allowing test solution:

private static final int nb_players = 4; private static final int nb_iterations = 1000000;  public static void main(string[] args) {     double totalprofit = 0.0d;     (int = 0; < nb_iterations; i++) {         int nbgoingforexpensive = 0;         (int j = 0; j < nb_players; j++) {             if ( goforbiggerresource() ) {                 nbgoingforexpensive++;             } else {                 totalprofit++;             }         }         totalprofit += nbgoingforexpensive > 0 ? 2 : 0;     }     double payoff = totalprofit / (nb_iterations * nb_players);     system.out.println( "payoff per player: " + payoff ); } 

for example if suggest following solution:

private static boolean goforbiggerresource() {     return true; }; 

then 4 players go bigger resource. 1 of them it, @ random. on 1 million iteration average payoff per player 2/4 gives 0.5 , program shall output:

payoff per player: 0.5

my question simple: should go method goforbiggerresource() (which returns either true or false) maximize average payoff , why?

since each player uses same strategy described in goforbiggerresource method, , try maximize overall payoff, best strategy 3 players sticking local resource , 1 player going big game. unfortunately since can not agree on strategy, , assume no player can not distinguished big game hunter, things tricky.

we need randomize whether player goes big game or not. suppose p probability goes it. separating cases according how many big game hunters there are, can calculate number of cases, probabilities, payoffs, , based on this, expected payoffs.

  • 0 bgh: (4 choose 0) cases, (1-p)^4 prob, 4 payoff, expected 4(p^4-4p^3+6p^2-4p+1)
  • 1 bgh: (4 choose 1) cases, (1-p)^3*p prob, 5 payoff, expected 20(-p^4+3p^3-3p^2+p)
  • 2 bgh: (4 choose 2) cases, (1-p)^2*p^2 prob, 4 payoff, expected 24(p^4-2p^3+p^2)
  • 3 bgh: (4 choose 3) cases, (1-p)*p^3 prob, 3 payoff, expected 12(-p^4+p^3)
  • 4 bgh: (4 choose 4) cases, p^4 prob, 2 payoff, expected 2(p^4)

then need maximize sum of expected payoffs. -2p^4+8p^3-12p^2+4p+4 if calculated correctly. since first term -2 < 0, concave function, , 1 of roots derivative, -8p^3+24p^2-24p+4, maximize expected payoffs. plugging online polynomial solver, returns 3 roots, 2 of them complex, third being p ~ 0.2062994740159. second derivate -24p^2+48p-24 = 24(-p^2+2p-1) = -24(p-1)^2, < 0 p != 1, indeed found maximum. (overall) expected payoff polynomial evaluated @ maximum, around 4.3811015779523, 1.095275394488075 payoff per player.

thus winning method this

private static boolean goforbiggerresource () {     return math.random() < 0.2062994740159; } 

of course if players can use different strategies and/or play against each other, it's entirely different matter.

edit: also, can cheat ;)

private static int cheat = 0;  private static boolean goforbiggerresource () {     cheat = (cheat + 1) % 4;     return cheat == 0; } 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -