#C6.txt: Feb. 11, 2013 Conway's games #Game is a PAIR [L,R] of sets of simpler games Help:=proc(): print(` GamesD1(k), GamesD(k) `): print(`RandGame(k,m), Age(G) , CanLeftWin(G), CanRightWin(G) `): print(`WhatKind(G)`) end: with(combinat): #GamesD1(k): all the games created in day<=k GamesD1:=proc(k) local L,R,S: option remember: if k=0 then RETURN({[{},{}] }): fi: S:=powerset(GamesD1(k-1)): { seq(seq( [ L, R], L in S), R in S) }: end: GamesD:=proc(k): GamesD1(k) minus GamesD1(k-1): end: #RandGame(k,m): a random game created in day <=k #where L and R are always of size <=m RandGame:=proc(k,m) local L,R,m1,m2,k1,i: if k=0 then RETURN([{},{}]): fi: m1:=rand(0..m)(): m2:=rand(0..m)(): L:={}: for i from 1 to m1 do k1:=rand(0..k-1)(): L:=L union {RandGame(k1,m)}: od: R:={}: for i from 1 to m2 do k1:=rand(0..k-1)(): R:=R union {RandGame(k1,m)}: od: [L,R]: end: #Age(G):the age of G=[{L},{R}] Age:=proc(G) local L,R: if G=[{},{}] then RETURN(0): fi: max(seq(Age(L), L in G[1]), seq(Age(R), R in G[2]))+1: end: #CanLeftWin(G): Can Left win the game G? CanLeftWin:=proc(G) local L: option remember: #if true in {seq(not CanRightWin(L), L in G[1])} then #RETURN(true): #fi: #false: evalb(true in {seq(not CanRightWin(L), L in G[1])}): end: #CanRightWin(G): Can Left win the game G? CanRightWin:=proc(G) local R: option remember: #if true in {seq(not CanLeftWin(R), R in G[2])} then # RETURN(true): #fi: #false: evalb(true in {seq(not CanLeftWin(R), R in G[2])}): end: #WhatKind(G): Is the game # WhatKind:=proc(G) local a,b: a:=CanLeftWin(G): b:=CanRightWin(G): if a and b then "Fuzzy": elif a and not b then "Positive": elif not a and b then "Negative": else "Zero" : fi: end: