4
$\begingroup$

I was thinking of determining the game of war. I could write a fairly simple game that takes two "decks" of cards, and plays them against each other but I do not think this is optimal.

Because in war the order of the cards matter it is also not a question of simply summing up the "power" of the cards. If the decks were Q-Q-J-J and K-K-1-1 then the game would go as follows even though the first player has more power:

Q-K (QJJ, K11)

Q-K (JJ, 11QK)

J-1 (J, 1QKQK)

J-1 (1J, QKQK)

1-Q (J1J, KQK)

J-K (1J, QK1Q)

1-Q (J, QK1QJK)

J-K (͏∅, K1QJK1Q)

∅ (͏∅, 1QJK1QJK)

I've been trying to think of a method of determine the winner of the game without going through the entire deck each and every time (and thus possibly going for thousands of iterations.)

If you could provide me with some pointers to start thinking about this question - that would be great!

I wasn't exactly sure where to ask this question: so if this is off topic here please redirect me.

$\endgroup$
  • $\begingroup$ Initially I don't want to care about "ties" but in the real game players "hide" 3 cards and show the 4th. The winner takes all. $\endgroup$ – Good Person Apr 22 '11 at 22:24
  • 2
    $\begingroup$ You may or may not be aware that a (deterministic) game of war may be periodic, so deciding the winner isn't as trivial as it first seems; you have to watch out for repeated game states. See mathoverflow.net/questions/11503/… $\endgroup$ – Ross Churchley Apr 23 '11 at 6:00
  • $\begingroup$ @Ross: Yes, the worst case O is O(∞); I am thinking about the average case. Thank you for pointing me to that question though $\endgroup$ – Good Person Apr 24 '11 at 0:30
  • $\begingroup$ The worst case isn't O(infinity), since you can of course always detect the loop! (And if it were, it would immediately imply that your average case was O(infinity) too, since the worst case occurs with non-zero probability!). I think this is an interesting question, but might be better suited for math.stackexchange.com (which handles more 'recreational' questions); try there, maybe? $\endgroup$ – Steven Stadnicki Jun 25 '11 at 2:26
4
$\begingroup$

I've been working on war for the past couple of days.

In particular I've been interested in the longest possible game, given no cycles. By backtracking, starting from the end position, I managed to avoid anything that goes into cycles. I used a dynamic greater-than relation to avoid having to decide what cards had what value from the start.

Even with those optimizations, I've only managed to create the following table, where the left column is the number of cards in play, and the right column is the length of the longest possible game:

1   0       13  62
2   1       14  467
3   3       15  85
4   7       16  261
5   9       17  107
6   17      18  >=935
7   17      19  137
8   29      21  168
9   31      23  209
10  53          
11  45          
12  79          

Interestingly I found, that odd number of cards, give a much larger chance of cycles. This makes it much easier to find the longest game, as there are far fewer positions to consider. The maximum length of these games is ery close to a second order polynomial.

$\endgroup$
  • $\begingroup$ Could you explain what you mean by branch-n-bound? $\endgroup$ – Good Person Jun 24 '11 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.