Tuesday, September 8, 2015

Cookie Take-Away

POP QUIZ: Whats better than eating cookies and playing games? (Trick question) There is NOTHING better. 

In this post, I am going to talk about specific type of take-away game. Lucky for us, it deals with theories and examples from both "The game of Nim" (where two players take turns removing sticks from a pile, thank you Bayard) and the Sprague-Grundy theories (which allows us to find P-positions and N-positions if you are able to decipher the pattern, thanks you Sam).

Cookie Take-Away! (Yumm)

Cookie Take-Away is a combinatorial game where two players take turns removing a single cookie every day for a certain number of days. Some cookies may "go bad" while on the shelf and it becomes unsafe to eat, with each cookie having an expiration date written on it with frosting. A cookie is represented by a heap of n counters, where n is the number of days remaining before the cookie goes bad. So if a cookie has a heap size of 0, then that cookies time has expired.  The winner is not the player who eats the most amount of cookies, but the winner is the player who has the joy of eating that last, delicious, mouth watering, cookie.

A turn consists of removing a single, non-empty heap (cookie) and reducing all other heaps by 1 number (one day closer to expiration). Once again, the player who removes the last, non-expired cookie, is the winner. So if we were to represent each position in a non-descending order(which will be called the components of the position), a simple example would be [1 2 4] which signifies a three-heap set with heap sizes of 1,2, and 4. The game with [1 2 4] would be played out as follows:


Reduction Theorems


A game that starts with n-heaps must terminate in a finite number of (at most n) moves, one of the two players must have a winning strategy. If the game was just with the set [1], the first player would win no matter what. However, using the same initial set of [1 2 4], the second player would guarantee a win no matter what move the first player would do:

As a refresher, a P-position is a move that "ensures a route" to victory and an N-position is move that allows you to get back to a P-Position. 

In the game of Cookie Take-Away, the set of [1] would be an N-type (wins for the next player) and if a set if not an N-position, it is called a P-type (the terminal position or a win for the "previous" player / win for the player who got it to that position), as seen in the set of [1 2 4]. So if one could determine, as the game progressed, if the set was an N or a P type, then that player would be guaranteed a win.  If two arbitrary sets of G and H happen to be the same type, then we would say "G~H" or tantamount. So the set of [1 5 6 7] ~ [1 4 4 4] because the size of the heap does not matter if it is greater than the maximum possible moves in a game (the size of n), which is equivalent to the number of heaps at the start of the game. We can also see that the set [1 1 2] ~ [1 2] as only k heaps of size k will be relevant while developing a strategy, since the others will "tarnish" before they can be taken.

Depletion Theorem: If G were a set [ a1, a2, .... , an], then any component of size greater than n may be depleted down to size n without affecting the type of set.

Deletion Theorem: Let G be the set [a1,a2, ... , an]. If ak < k for some k, then the component of a1 may be deleted without affecting the type of set. A Surplus of G is the smallest non-integer s where k - ak < s for all 1 < k < n. So whenever s > 0, the set [ a1, a2, ... as] may all be deleted. This basically says to delete the s smallest components, where s is the surplus of the position.

So [1 2 3 3 6] ~ [ 1 2 3 3 5]. The set has surplus of 4 - a4 = 4 - 3 = 1, thus making it 
tantamount to [ 2 3 3 5] or [ 2 3 3 4] 

Proofs of these two theorems can be found at this journal entryhere

(I know this may not make much sense right now, but stay with me)

Using both depletion and deletion, one can convert each set into a reduced form of that same set and type. You may be asking "why would I want to do this?" - well hear me out. If we were to replace all the heaps of size > n by heaps that are effectively infinite (denoted by "*"), then we could have cookies that have an "infinite expiration date", which makes it much more clear as to why depletion and deletion is helpful. So when going through these steps, we want to DELETE as many times as possible, and then DEPLETE. 

So the set [ 1 2 3 3 6] ~ [ 1 2 3 3 *]. Then you delete the smallest component,
which gives us [ 2 3 3 6] ~ [2 3 3 *]. Then you deplete the largest component,
which gives us [ 2 3 3 4] 


So take a look at all of the possible reduced sets which have 4 or less components. You can see that if a set is in the N-position, then the winning move is the move that is circled. (Remember that a move is winning if that move/component leads to a P-position) 




Hmmm. This may be an interesting pattern. 


Here is a table that shows all sets from 1 2 .... n

If you haven't realized it yet, there are numerous interesting patterns that apply to each of these sets (with the exception of n = 1):

1) For n = 0 mod 3, the set is a P-type.
2) For n = 1 mod 3, the moves that would win you the game are 1, ... , 2/3 (n - 1)
3) For n = 2 mod 3, the moves that would win you the game are 2/3(n + 1), ... , n.

So....The table below gives a value for both a and n, where the winning moves are the ones shown. If it is blank, that means there is no possible winning move because that set is a P-type. 



**Consistent pattern all the way up to n = 20, stopped as author saw sufficient data**

The line shown in the table divides it up into three segments. There is one containing the set [1], and two that are infinite, and are determined by whether or not n is > 2a - 2 or < 2a - 2.

However, you can still follow the simple rule (although it may not be that clear) of: if the largest move is congruent to 0 mod 3, 1 mod 3, or 2 mod 3, then you would either select indifferently, move with the smallest number possible, or move with the largest number possible. (Further Explained in greater detail in Proof link) 


Sprague-Grundy Values! 





Above is what the graph that you just saw in table 3, but converted into the Sprague-Grundy values. Here are some things that you should note down from this new board for figuring out values that go beyond this board:
  1. Above the drawn in diagonal line (n > 2a - 2), you see that the values stay consistent on the northeast-to-southwest diagonal.
  2. Also above the drawn in diagonal line, you will notice that the same repeating periodic sequence (Shout out to Lauren Q.) of 0,1,2,0,1,3,...,0,1,2,0,1,3. 
  3. Below the diagonal drawn in line, the grundy values remain consistent as you go down a column. 

What do these values tell you?

First, you need to know what strict positions are. Strict positions are sets that range from a1 to an, they have grundy values of 0,1,2, or 3, and all of its components are distinct, excluding those components of size n. (This is the case because of the Depletion theory explained earlier. The set [ 2 3 4 ] ~ [ 2 3 3 ].)

Winning Conjecture! 

**variables with parentheses next to them should be depicted as subscripts
The winning conjecture says that: If G is a strict position of N-type, then the winning components of G are exactly those whose size lie in a specific "winning interval", which would be a(i), a(i+1), ...,  a(j), as long as that list of natural numbers are uninterrupted. But this ONLY works for strict positions. For example, the set [ 1 2 2 3 6 6 ] does not have a winning conjecture because the winning moves are both the 2's and the 6's. 



Final Thoughts?

And thats, that! Cookie Take-Away is a great fun game as it deals the factor of "expiration" to the already popular variation of the game Nim. If you're able to think ahead to where you could set yourself up to eat the last, healthy cookie, then you could be quite good at this game. But its interesting to think about if the same patterns on the grundy table follow all the way out to infinity, I mean who knows right? Anyways, Ive been writing this blog about cookies for a solid amount of hours now so Im kind of hungry. What are your favorite flavors of cookie? Let me know below!




Best of wishes,

                      Jon D.


References:
http://faculty.uml.edu/jpropp/cookie1.pdf
http://faculty.uml.edu/jpropp/cookie2.pdf


10 comments:

  1. Awesome post Jon! Lots of interesting information that I can't wait to hear more about in class. I didn't quite understand the definition of tantamount, maybe we could go over this in class! Thanks!

    yours truly,
    Lauren :)

    ReplyDelete
    Replies
    1. Hey Lauren. Hope this helps, but tantamount is another way of saying equivalent. So G is equivalent to H in the example Jon used.

      Also, my favorite cookies are Oreos (NOT oreo thins) if they are from the store or no-bake cookies if they are made at home. Please do NOT bring chips ahoy to class tomorrow. Thanks!

      Delete
  2. Excellent post Jon! There are many interesting examples that I want to hear further explanation tomorrow in class. Also there is some information that I don't understand very well like the Depletion Theorem that I'm exciting to hear more about. You introduced tantamount under Reduction Theorem, is G~H can be regarded as G is isomorphic to H? I don't know if isomorphic exists in Game Theory area, but if that's the case, it would be much easier to understand! Thank you very much and look forward to hearing more tomorrow!

    The best,
    Amber

    ReplyDelete
    Replies
    1. Good question, Amber!

      The concept of "isomorphic" DOES exist in game theory! Here we saw an example of equivalence classes of positions (i.e. two positions can be "tantamount" to each other). But we can also have two games be isomorphic to each other! Here is a really neat example that is worth thinking about. COINSLIDE is a game played on a strip of squares numbered 1 through n (left to right). There is at most one coin per square. A legal move is to slide a coin to the left (i.e. to a lower numbered square)---jumping over another coin or sliding off the edge of the strip is not allowed. So here is an example of a position:
      [img]http://myslu.stlawu.edu/~nkomarov/450/Screenshot%202015-09-11%2017.06.17.png[/img]
      In this position, the coin on 1 cannot move, the coin on 5 can move to any square numbered 2 through 4, and the coin on 7 can move only to square 6.

      So here is the question: What other game is COINSLIDE equivalent to? Spoiler: the answer is going to be NIM because the answer to a question like this is almost always NIM, but it isn't all that obvious how, exactly. What do the NIM-heap-sizes correspond to in COINSLIDE?

      Delete
  3. also I almost forgot:
    my favorite cookies are chocolate chip (not chips ahoy), oreo's, or cookie brownies, icing preferred too!

    ReplyDelete
  4. Great post and presentation Jon!
    While playing the couple sample games at the end I was interested to see how simple it was to find out who won or lost, based on who was up first. The numbers/expiration dates that we were working with, were relatively high, and most lasted the majority of the game. But I was curious to see what happened if a larger amount of the cookies had lower expiration dates. I wanted to see if there were multiple times that the person up could take charge of the game or take back charge of the game. Which I am sure there is, and it also all depends on the pattern of the dates. However after running through multiple of games that I created, there is usually a set winner. I found one case where I believe either player can win. If someone could confirm that would be great.
    1 2 3 4 1 6 7 1 2 3
    Taking the 6 or 7 first, I found that the second player had the chance to win. Other cases, I found that the first player won. But I am not sure of this, so i would love for a second set of eyes
    Sam

    ReplyDelete
    Replies
    1. Hey Sam! So, actually the theory of N and P positions tells us that every position is either N or P--meaning it can't be both. If what you say is true that taking 6 or 7 first makes the game second player win but the other choices make it first player win---the first player would never start with 6 or 7. :) One good move for the first player to play is to take the cookie with expiration time 4. You can do a game tree analysis (i.e. draw out all the "branches" of the tree which correspond to every possible move that can be made and see if they are N or P positions) to see that this brings the game to a P-position (taking the 4-cookie brings us to 1 2 5 6 1 2; which by the way we should probably right in increasing order to make it easier to see-- 1 1 2 2 5 6). To prove that 1 1 2 2 5 6 is a P-position, we'd need to check out all of the possible moves (taking one of the 1-cookies, one of the 2-cookies, the 5-cookie, or the 6-cookie) and see that each of those brings us to an N-position. This actually doesn't take TOO long:
      * Taking a 1-cookie brings us to position 1 1 4 5. The next player here can win by taking, e.g., one of the 1-cookies, and getting to position 3 4, which is a losing (i.e. P) position. So 1 1 4 5 is an N-position.
      * Taking a 2-cookie brings us to position 1 4 5. The next player can again win by taking the 1-cookie and getting to 3 4, which is a P position.
      * Taking a 5-cookie brings us to position 1 1 5. The next player can win in one move by taking the 5-cookie (and letting the other 2 expire).
      * Taking a 6-cookie brings us to position 1 1 4, which is the same as the last case.

      So all of these moves are to N-positions, making 1 1 2 2 5 6 a P-position.

      OK, that was kind of long, but hopefully if you follow through it carefully you'll see that it shows that the initial position you came up with is an N-position (i.e. Player One will be able to force a win no matter what Player Two counters with).

      Good question!!

      Delete
    2. Oops... Write, not right. 😑

      Delete
  5. Jon, I was amazed at the theoretical complexity of such a seemingly simple game. I was impressed with your discussion of the topic. The fact that this game has different "days" and times of expiration kind of made me think of Conway's Game of Life. I had talked about the game with my advisor at the beginning of the semester, and it sounded pretty cool. So, in Conway's game there is an orthogonal grid of square "cells." Cells will die when they have fewer than two live neighbors, as if by under-population. Cells with two or three live neighbors live on to the next generation. Cells with more than three live neighbors will die due to overcrowding. Finally, dead cells with exactly three live neighbors will be revived. The game is called a zero-player game, meaning that the game starts with an initial configuration and continues infinitely based on the rules described. There are some pretty cool patterns that arise!
    (Check it out!! http://pmav.eu/stuff/javascript-game-of-life-v3.1.1/)
    Anways...the games are obviously very distinct, but I guess the concept of expiration over time sounded familiar.

    ReplyDelete
  6. Figuring out the example games at the end of your presentation was a very fun experience. Learning about the definitions of deletion and depletion in class, then figuring out how to apply them, finally resulting in using them in some random games was surprisingly satisfying. The game was also surprisingly robust given how seemingly simple the premise was, and I'm glad you were able to help us all learn the tricks to simplify the complications.
    Not that this needs to become more complicated, but I wonder what would happen if we made this game into a take-or-break game. That is, you could take a cookie, or break it into two cookie pieces, where we would make rules to determine how the expiration date of the two cookie pieces would work. Could be fun.
    Nothing beats samoas.

    ReplyDelete