Composite Mathematical Games

Embed Size (px)

Citation preview

  • 8/7/2019 Composite Mathematical Games

    1/37

    D e p a r t m e n t o f C o m p u t e r S c i e n c e

    F a c u l t y o f M a t h e m a t i c s , P h y s i c s a n d I n f o r m a t i c s

    C o m e n i u s U n i v e r s i t y

    C o m p o s i t e m a t h e m a t i c a l g a m e s

    V O 2 0 0 7

    R a s t i s l a v L e n h a r d t

    A d v i s o r :

    D o c . R N D r . R a s t i s l a v K r o v i , P h D . B r a t i s l a v a , 2 0 0 7

  • 8/7/2019 Composite Mathematical Games

    2/37

    A b s t r a c t

    D e c o m p o s i t i o n o f m a t h e m a t i c a l g a m e s t o s m a l l e r p a r t s i s e s s e n t i a l b e c a u s e o f t h e

    l a r g e n u m b e r o f p o s s i b l e p o s i t i o n s . W e h a v e s t u d i e d t h e d e g e n e r a t e d v a r i a t i o n o f t h e

    f a m o u s D o t s a n d B o x e s g a m e w h e r e t h e w i n n e r i s a p l a y e r w h o r s t c r e a t e s t h e r s t

    b o x . T h i s v a r i a t i o n i s s t r o n g l y r e l a t e d t o t h e o r i g i n a l g a m e a n d c a n o f t e n h e l p u s t o

    n d a s t r a t e g y f o r t h e o r i g i n a l g a m e . W e h a v e f o u n d a n d p r o v e d w h i c h p l a y e r h a s

    a w i n n i n g s t r a t e g y i f w e s t a r t f r o m t h e i n i t i a l e m p t y b o a r d . F o r a r b i t r a r y p o s i t i o n s

    w e f o u n d o u t t h a t t h e g a m e i s b e i n g d e c o m p o s e d t o t h e s m a l l e r s u b g a m e s w h e r e

    t h e w i n n e r i s a p l a y e r w h o w i n s t h e r s t o f t h e s e s u b g a m e s . W e h a v e i n t r o d u c e d

    w - f u n c t i o n t h a t a s s i g n s w - n u m b e r s t o t h e p o s i t i o n s o f s u b g a m e s a n d b y c o m b i n i n g

    t h e s e v a l u e s w e c a n n d t h e w - n u m b e r a n d t h u s w h o h a s a w i n n i n g s t r a t e g y i n

    t h e c o m p o s i t e g a m e s o f t h i s t y p e . T h e s e r e s u l t s a l l o w u s t o n d s o l u t i o n s t o t h e s e

    g a m e s m u c h f a s t e r . I f n i s t h e s i z e o f t h e s u b g a m e s a n d k n u m b e r o f s u b g a m e s

    t h e n t h e c o m p l e x i t y i s o n l y O(kn) i n c o m p a r i s o n t o O(nk) o b t a i n e d b y t h e s t a n d a r d a l g o r i t h m . W e u s e d t h i s g e n e r a l c o n c e p t t o s o l v e t h e d e g e n e r a t e d D o t s a n d B o x e s

    g a m e . H o w e v e r i t c a n b e u s e d i n a n y o t h e r g a m e s d e c o m p o s i n g t h i s w a y . T h e r s t p a r t

    c o n t a i n s k n o w n w a y s o f a d d i n g i m p a r t i a l g a m e s w i t h p r o o f s a n d m a n y e x a m p l e s t o

    h e l p o r i e n t i n t h i s a r e a . W e h a v e c r e a t e d a l s o a c o m b i n a t o r i a l g a m e A P I t o s u p p o r t

    a n d i m p r o v e c o n d i t i o n s i n r e s e a r c h i n g t h e c o m b i n a t o r i a l g a m e s . A l m o s t a l l t h e s e

    g a m e s i n c l u d i n g t h e d e g e n e r a t e d D o t s a n d B o x e s g a m e a n d a l g o r i t h m s f o r c o m p o s i t e

    g a m e s a r e i m p l e m e n t e d i n t h i s A P I .

    2

  • 8/7/2019 Composite Mathematical Games

    3/37

    C o n t e n t s

    1 I n t r o d u c t i o n 4

    2 M a t h e m a t i c a l g a m e s 6

    2 . 1 D e n i t i o n s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

    2 . 2 B a s i c c o n c e p t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

    2 . 3 T h e G a m e o f N i m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

    3 K n o w n w a y s o f a d d i n g i m p a r t i a l g a m e s 9

    3 . 1 O r d i n a r y s u m o f g a m e s ( x o r ) . . . . . . . . . . . . . . . . . . . . . . . . . 9

    3 . 2 U n i o n o f g a m e s ( o r ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 0

    3 . 3 S e l e c t i v e c o m p o u n d ( a l m o s t o r ) . . . . . . . . . . . . . . . . . . . . . . . . 1 1

    3 . 4 C o n j u n c t i v e c o m p o u n d ( a n d ) . . . . . . . . . . . . . . . . . . . . . . . . . 1 2

    3 . 5 C o n t i n u e d c o n j u n c t i v e c o m p o u n d ( a l s o ) . . . . . . . . . . . . . . . . . . . . 1 4

    4 T h e D o t s a n d B o x e s g a m e 1 6

    4 . 1 D e g e n e r a t e v a r i a t i o n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 6

    4 . 2 S o l u t i o n f o r s t a r t i n g p o s i t i o n s o f d e g e n e r a t e v a r i a t i o n . . . . . . . . . . . . 1 7

    5 w - n u m b e r s 1 9 5 . 1 A l g o r i t h m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 0

    5 . 2 R e l a t i o n s h i p b e t w e e n w

    - n u m b e r s a n d G r u n d y n u m b e r s . . . . . . . . . . . 2 2

    5 . 3 A p p l i c a t i o n i n g a m e s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2

    6 T h e D o t s a n d B o x e s g a m e r e l o a d e d 2 4

    6 . 1 V a l u e s f o r s m a l l e r g a m e s . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 4

    6 . 2 C o m p u t a t i o n o f v a l u e s f o r b i g g e r g a m e s . . . . . . . . . . . . . . . . . . . . 2 5

    7 A P I f o r c o m b i n a t o r i a l g a m e s 2 7

    7 . 1 O v e r v i e w . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 7

    7 . 2 M o r e d e t a i l s o f t e c h n i c a l d e s i g n . . . . . . . . . . . . . . . . . . . . . . . . 2 8

    8 C o n c l u s i o n 3 3

    9 U p d a t e 3 4

    3

  • 8/7/2019 Composite Mathematical Games

    4/37

    1 I n t r o d u c t i o n

    T h e c o m b i n a t o r i a l g a m e t h e o r y i s a q u i t e n e w b r a n c h o f m a t h e m a t i c s . H o w e v e r , p e o p l e

    h a v e b e e n p l a y i n g g a m e s f o r a g e s . I t i s a n a t u r a l h u m a n b e h a v i o u r a n d o u r b a s i c i n s t i n c t

    t o c o m p e t e , h a v e f u n a n d d o m i n a t e t h e p e e r s . T h e r e a r e a p p l i c a t i o n s a n d c o n n e c t i o n s

    t o c o m p l e x i t y , l o g i c , g r a p h t h e o r y , n e t w o r k s , e r r o r c o r r e c t i n g c o d e s , d i s t r i b u t e d s y s t e m s ,

    s u r r e a l n u m b e r s a n d a n a l y s i s a n d d e s i g n o f m a t h e m a t i c a l a n d c o m m e r c i a l g a m e s .

    U n o c i a l l y w e c a n d i v i d e g a m e s i n t o t w o c a t e g o r i e s . I n t h e r s t t h e r e a r e g a m e s p e o p l e

    p l a y . I n t h e s e c o n d t h e r e a r e g a m e s m a t h e m a t i c i a n s p l a y . T h e r s t c a t e g o r y c o n t a i n s

    c h a l l e n g i n g g a m e s t h a t p e o p l e w i l l p u r c h a s e a n d p l a y . I t i s r e a l l y h a r d t o i n v e n t s u c h

    g a m e s . T h e y c a n n o t h a v e a s i m p l e w i n n i n g s t r a t e g y . B u t a t t h e s a m e t i m e t h e t h i n g t h a t

    m a k e s t h e m v e r y a m u s i n g a n d p o p u l a r i s t h a t e v e n a n i n e x p e r i e n c e d p l a y e r h a s a c e r t a i n

    f e e l i n g f r o m t h e p o s i t i o n . F o r e x a m p l e h e c a n s a y i f t h e p o s i t i o n i n a c h e s s g a m e i s s t r o n g

    o r w e a k f o r t h e c u r r e n t p l a y e r .

    A s J u d e a P e a r l w r o t e m a t h e m a t i c a l g a m e s o e r a p e r f e c t l a b o r a t o r y f o r s t u d y i n g c o m -

    p l e x p r o b l e m s o l v i n g m e t h o d o l o g i e s . W i t h a f e w r u l e s , o n e c a n c r e a t e c o m p l e x s i t u a t i o n s

    t h a t n e e d a h u g e a m o u n t o f i n s i g h t . D i c u l t y o f c o m b i n a t o r i a l g a m e s c a n b e s h o w e d b y

    c o m p a r i n g i t t o c r y p t o g r a p h y . I n a c r y p t o g r a p h y w e w a n t t o k n o w i f a c r y p t o s y s t e m t h a t

    a t t a c k s o n i t w i l l n o t b r e a k h i m . I n g a m e s w e h a v e a d e c i s i o n p r o b l e m . W e w a n t

    t o k n o w i f a m o v e f o r t h e r s t p l a y e r t h a t f o r o p p o n e n t ` s m o v e s a m o v e f o r t h e r s t p a l y e r t h a t

    . . .s u c h t h a t t h e r s t p l a y e r w i l l w i n ? W h a t m a k e s g a m e s e v e n h a r d e r i s t h a t

    w e a r e n o t p l a y i n g a g a i n s t a p a s s i v e o p p o n e n t l i k e w h e n w e a r e s o l v i n g N P - h a r d p r o b l e m s

    l i k e n d i n g H a m i l t o n i a n c y c l e o r T r a v e l l i n g s a l e s m a n p r o b l e m . O u r o p p o n e n t i n a g a m e

    i s t a k i n g a l l p o s s i b l e a c t i o n s a g a i n s t u s . S o w e o f t e n n e e d t o e x a m i n e t h e w h o l e d e c i s i o n

    s u b t r e e , n o t s i m p l y n d a p a t h .

    B u t n o t e v e r y t h i n g i s l o s t . F o r t u n a t e l y , w e c a n d o b e t t e r a n d p r o t f r o m t h e f a c t t h a t w e

    k n o w b e t t e r s t r u c t u r e s o f s o m e g a m e s . T h e e s s e n t i a l f a c t i s t h a t g a m e s a r e o f t e n c o m p o s e d

    f r o m m o r e d i s j u n c t i v e ( a n d s i m p l e r ) p a r t s . W e c a n p r e c o m p u t e s o m e i n f o r m a t i o n f o r p a r t s

    a n d t h e n a d d i t t o g e t h e r t o n d o u t t h e r e s u l t f o r t h e w h o l e g a m e . I t i s o n e o f t h e g o a l s o f

    t h i s t h e s i s t o r e v i e w e x i s t i n g w a y s o f a d d i n g i m p a r t i a l m a t h e m a t i c a l g a m e s t o h e l p o t h e r

    s t u d e n t s a t u n d e r g r a d u a t e l e v e l t o o r i e n t i n t h i s t o p i c . S o i n t h e t h i r d s e c t i o n a l g o r i t h m s

    c a n b e f o u n d f o r h o w t o p l a y d i e r e n t t y p e s o f c o m p o s i t e g a m e s w i t h p r o o f s a n d m a n y

    e x a m p l e s .

    T h e n e x t p a r t o f t h e t h e s i s i s m o r e r e s e a r c h o r i e n t e d . M r E l w y n B e r l e k a m p , a p r o f e s s o r

    a t U C B e r k e l e y , c o - a u t h o r o f b i b l e s o f c o m b i n a t o r i a l g a m e s [ W w 0 1 ] a n d a u t h o r o f [ B e 0 0 ] ,

    h a s p r o p o s e d t o m e a p r o b l e m i n t h e D o t s a n d B o x e s g a m e . T h e D o t s a n d B o x e s g a m e i s

    a g a m e p e o p l e p l a y , b u t i t i s e x a m i n e d a l o t b y m a t h e m a t i c i a n s , a s w e l l . W e h a v e b e e n

    r e s e a r c h i n g h o w t o p l a y d e g e n e r a t e v a r i a t i o n o f t h i s g a m e i n w h i c h a p l a y e r w h o c r e a t e s t h e

    r s t b o x w i n s . K n o w l e d g e o f h o w t o p l a y t h i s d e g e n e r a t e v a r i a t i o n c a n h e l p a l o t t o p l a y

    t h e o r i g i n a l g a m e . I n t h e f o u r t h s e c t i o n t h e r e a r e a n s w e r s f o r h o w t o p l a y t h i s d e g e n e r a t e

    g a m e f r o m t h e i n i t i a l e m p t y b o a r d . W h i l e l o o k i n g f o r a s t r a t e g y f o r a n y a r b i t r a r y p o s i t i o n s

    w e h a v e r e a l i s e d t h a t t h e g a m e i s b e i n g d e c o m p o s e d t o s m a l l e r s u b g a m e s , b u t w i t h a r u l e

    t h a t a p l a y e r w h o r s t w i n s o n e o f t h e s e s u b g a m e s w i n s t h e w h o l e g a m e . T h i s w a s d i e r e n t

    4

  • 8/7/2019 Composite Mathematical Games

    5/37

    f r o m a l l k n o w n w a y s p r e s e n t e d i n t h e t h i r d s e c t i o n . S o f r o m t h e c o n c r e t e g a m e w e g e t t o

    t h e n e w g e n e r a l p r o b l e m , b u t w e m a n a g e d t o s o l v e i t . W e i n t r o d u c e d a n e w w

    - f u n c t i o n

    t h a t a s s i g n s

    w- n u m b e r t o e v e r y p o s i t i o n . T h e n w e c a n c o m b i n e t h e s e

    w- n u m b e r s t o n d

    o u t i f t h e r s t o r t h e s e c o n d p l a y e r h a s t h e w i n n i n g s t r a t e g y . B u t t h e s e n u m b e r s r e p r e s e n t

    a l s o t h e w h o l e s u m o f p a r t s . I f w e w a n t t o a d d a n o t h e r p a r t t o t h i s c o m p o u n d w e j u s t n e e d

    t o c o m b i n e i t s w

    - n u m b e r w i t h t h e w

    - n u m b e r o f t h e s u m o b t a i n e d b e f o r e . T h i s r e s u l t a l l o w s

    u s t o n d r e s u l t s m u c h f a s t e r . W e c a n d e c r e a s e c o m p l e x i t y f r o m O(nk)

    t oO(kn)

    w h e r e

    ni s a n u m b e r o f p o s i t i o n s o f s u b g a m e a n d

    kn u m b e r o f s u b g a m e s . I t i s v e r y i m p o r t a n t ,

    b e c a u s e n

    i s o f t e n v e r y h i g h . T h e s o l u t i o n t o t h i s c o m p o u n d f o r a n y g a m e s i s p r e s e n t e d i n

    S e c t i o n 5

    . L a t e r i t i s i m p l e m e n t e d a n d u s e d f o r s o l v i n g t h e d e g e n e r a t e d v a r i a t i o n o f t h e

    D o t s a n d B o x e s g a m e . H o w e v e r t h i s g e n e r a l c o n c e p t c a n b e u s e d t o n d s o l u t i o n s t o a n y

    o t h e r g a m e s t h a t d e c o m p o s e t h i s w a y .

    A l m o s t a l l a l g o r i t h m s a r e i m p l e m e n t e d a n d a l l c o n c r e t e r e s u l t s g a i n e d b y u s i n g n e w l y

    d e v e l o p e d C o m b i n a t o r i a l g a m e A P I . I t i s a n o p e n a n d c a r e f u l l y d e s i g n e d t o o l c r e a t e d t o

    s u p p o r t a n d i m p r o v e c o n d i t i o n s i n r e s e a r c h i n g t h e c o m b i n a t o r i a l g a m e s . I t w o u l d b e a l m o s t

    i m p o s s i b l e t o g e t a n d c h e c k a n y r e s u l t s w i t h o u t h a v i n g s u c h a t o o l

    1

    . T h e w h o l e A P I w i t h

    s o u r c e c o d e s i s a n a t t a c h e m e n t t o t h i s t h e s i s .

    I w o u l d l i k e t o t h a n k m y t h e s i s a d v i s o r R a s t i s l a v K r o v i f o r h i s t i m e , v a l u a b l e f e e d b a c k

    a n d a l o t o f a d v i c e . I w o u l d a l s o l i k e t o t h a n k t o m y f a m i l y a n d f r i e n d s f o r a l l t h e i r l o v e

    a n d s u p p o r t .

    R a s t i s l a v L e n h a r d t

    1

    Y o u a r e a s s t r o n g a s y o u r t o o l s a l l o w y o u t o b e .

    5

  • 8/7/2019 Composite Mathematical Games

    6/37

    2 M a t h e m a t i c a l g a m e s

    M a t h e m a t i c a l g a m e s a r e t w o - p e r s o n g a m e s w i t h p e r f e c t i n f o r m a t i o n a n d n o c h a n c e m o v e s ,

    a n d w i t h a w i n - o r - l o s e o u t c o m e . P l a y e r s a r e u s u a l l y a l t e r n a t i v e l y m o v i n g u n t i l t h e y r e a c h

    a t e r m i n a l p o s i t i o n . T h e t e r m i n a l p o s i t i o n i s p o s i t i o n f r o m w h i c h n o p o s s i b l e m o v e s a r e

    p o s s i b l e . A f t e r t h a t o n e p l a y e r i s d e c l a r e d t h e w i n n e r a n d t h e o t h e r t h e l o s e r .

    2 . 1 D e n i t i o n s

    D e n i t i o n 2 . 1 . T h e g a m e G i s a m a t h e m a t i c a l ( c o m b i n a t o r i a l ) g a m e i f i t s a t i s e s t h e f o l l o w i n g p r o p e r t i e s :

    1 . T h e r e a r e t w o p l a y e r s .

    2 . T h e r e i s a n i t e s e t X o f p o s s i b l e p o s i t i o n s o f t h e g a m e .

    3 . T h e r u l e s o f t h e g a m e s p e c i f y f o r b o t h p l a y e r s a n d e a c h p o s i t i o n w h i c h m o v e s t o o t h e r

    p o s i t i o n s a r e l e g a l m o v e s .

    4 . T h e p l a y e r s a l t e r n a t e m o v i n g .

    5 . T h e g a m e G e n d s w h e n t h e r e i s n o p o s s i b l e m o v e f r o m t h e p o s i t i o n f o r t h e p l a y e r w h o s e t u r n i t i s .

    6 . T h e g a m e e n d s i n a n i t e n u m b e r o f m o v e s n o m a t t e r h o w i t i s p l a y e d .

    D e n i t i o n 2 . 2 . G a m e G i s i m p a r t i a l i f f o r e a c h p o s i t i o n x X t h e r e a r e t h e s a m e o p t i o n s ( p o s s i b l e m o v e s ) f o r b o t h p l a y e r s . O t h e r w i s e g a m e G i s c a l l e d p a r t i z a n .

    D e n i t i o n 2 . 3 . U n d e r t h e n o r m a l p l a y r u l e , t h e l a s t p l a y e r t o m o v e w i n s ( t h e p l a y e r

    w h o i s u n a b l e t o m o v e l o s e s ) .

    D e n i t i o n 2 . 4 . U n d e r t h e m i s r e p l a y r u l e , t h e l a s t p l a y e r t o m o v e l o s e s .

    C o r o l l a r y 2 . 1 . I m p a r t i a l g a m e G i s d e t e r m i n e d b y a s e t o f p o s i t i o n s X, i n c l u d i n g a n i n i t i a l p o s i t i o n x0 X, m o v i n g f u n c t i o n f : X 2

    Xt h a t r e t u r n s p o s i t i o n s t o w h i c h a

    p l a y e r c a n m o v e f r o m e v e r y p o s i t i o n

    x Xa n d w i n n i n g c o n d i t i o n .

    I n t h i s t h e s i s ( i f n o t s t a t e d e x p l i c i t l y o t h e r w i s e ) w e w i l l m e a n b y g a m e G

    a n i m p a r t i a l

    g a m e p l a y e d u n d e r n o r m a l p l a y r u l e . T h e p l a y e r w h o s t a r t s t h e g a m e w i l l b e c a l l e d F i r s t

    a n d t h e o t h e r o n e w i l l b e c a l l e d S e c o n d .

    E x a m p l e 2 . 1 . C a r d s a r e n o t a m a t h e m a t i c a l g a m e b e c a u s e p l a y e r s d o n o t h a v e p e r f e c t

    i n f o r m a t i o n a b o u t t h e p o s i t i o n .

    E x a m p l e 2 . 2 . T i c - T a c - T o e i s a m a t h e m a t i c a l g a m e , b u t i t i s p a r t i z a n ( n o t i m p a r t i a l ) ,

    b e c a u s e o n e p l a y e r c a n m a k e o n l y X ` s a n d o t h e r o n l y O ` s .

    6

  • 8/7/2019 Composite Mathematical Games

    7/37

    2 . 2 B a s i c c o n c e p t

    D e n i t i o n 2 . 5 . E v e r y p o s i t i o n i n g a m e G i s e i t h e r a W i n n i n g p o s i t i o n ( o f t e n c a l l e d W -

    p o s i t i o n ) o r L o s i n g p o s i t i o n ( L - p o s i t i o n ) . W i n n i n g p o s i t i o n s a r e a l l p o s i t i o n s f r o m w h i c h

    p l a y e r w h o s e t u r n i t i s c a n f o r c e a w i n a g a i n s t h i s o p p o n e n t .

    P o s i t i o n s o f e v e r y g a m e h a v e f o l l o w i n g p r o p e r t i e s :

    A l l t e r m i n a l p o s i t i o n s a r e L - p o s i t i o n s .

    I f a p l a y e r i s a b l e t o m o v e f r o m p o s i t i o n

    xt o L - p o s i t i o n t h e n

    xi s W - p o s i t i o n .

    I f a p l a y e r i s a b l e t o m o v e f r o m p o s i t i o n

    xo n l y t o W - p o s i t i o n s t h e n

    xi s L - p o s i t i o n .

    T h e s e p r o p e r t i e s l e a d t o s t r a i g h t f o r w a r d r e c u r s i v e i m p l e m e n t a t i o n o f a l g o r i t h m . W h i l e

    w e h a v e o n l y n i t e l y m a n y p o s i t i o n s w e c a n s t e p b y s t e p l a b e l a l l o f t h e m e i t h e r W - p o s i t i o n

    o r L - p o s i t i o n .

    N o t e 2 . 1 . W h i l e a p l a y e r c a n l o s e o n l y i f h e c a n n o t m o v e , h e c a n s e c u r e a w i n b y n d i n g

    a s t r a t e g y t h a t w i l l g i v e h i m i n a l l s t a g e s o f t h e g a m e a t l e a s t o n e p o s s i b l e m o v e .

    R u l e s 2 . 1 ( L i m i t e d N i m )

    . L i m i t e d N i m i s a g a m e p l a y e d w i t h n c o i n s a n d d e n e d n i t e s u b s t r a c t i o n s e t S Z+ . T h e p l a y e r w h o s e t u r n i t i s t a k e s a w a y k c o i n s , w h e r e k S. I fh e i s u n a b l e t o m o v e h e l o s e s .

    E x a m p l e 2 . 3 . L i m i t e d N i m G a m e w i t h

    11c o i n s a n d s u b s t r a c t i o n s e t

    S = {1, 3, 4} :

    n 0 1 2 3 4 5 6 7 8 9 1 0 1 1

    p o s i t i o n L W L W W W W L W L W W

    2 . 3 T h e G a m e o f N i m

    T h e m o s t f a m o u s m a t h e m a t i c a l g a m e i s p r o b a b l y t h e G a m e o f N i m .

    R u l e s 2 . 2 ( T h e G a m e o f N i m )

    . T h e r e a r e n p i l e s o f c o i n s . W h e n i t i s a p l a y e r ` s t u r n h e c h o o s e s o n e p i l e a n d t a k e s a w a y a t l e a s t o n e c o i n f r o m i t . I f s o m e o n e i s u n a b l e t o m o v e h e

    l o s e s ( s o t h e o n e w h o r e m o v e s t h e l a s t c o i n i s t h e w i n n e r ) .

    I f t h e r e i s o n l y o n e p i l e , t h e s o l u t i o n i s s i m p l y t o r e m o v e a l l c o i n s . I f t h e r e a r e t w o p i l e s

    w e k n o w t h a t t h e t e r m i n a l p o s i t i o n i s (0, 0)

    . W e c a n u s e t h e p o w e r o f s y m m e t r y t o o b t a i n

    t h a t o n l y (x, x)

    a r e l o s i n g p o s i t i o n s . I f o n e p l a y e r m o v e s f r o m t h i s p o s i t i o n , t h e s e c o n d

    p l a y e r c a n r e t u r n t o t h i s p o s i t i o n b y t a k i n g t h e s a m e n u m b e r o f c o i n s f r o m a n o t h e r p i l e .

    T h e r e f o r e t h e s e c o n d p l a y e r h a s a l w a y s t u r n s o h e w i l l w i n .

    F i n d i n g p a t t e r n s f o r t h r e e a n d m o r e p i l e s i s n o t s o s i m p l e . T h e i d e a b e h i n d t h e s o l u t i o n

    i s t h e f o l l o w i n g e q u i v a l e n t g a m e .

    7

  • 8/7/2019 Composite Mathematical Games

    8/37

    F i g u r e 1 : E x a m p l e o f L - p o s i t i o n i n C h e s s b o a r d N i m ( a l l c o l u m n s w i t h e v e n n u m b e r o f

    c o i n s )

    R u l e s 2 . 3 ( C h e s s b o a r d N i m )

    . C o n s i d e r a c h e s s b o a r d w i t h n r o w s . A t t h e b e g i n n i n g t h e r e a r e c o i n s o n s o m e s q u a r e s o f t h e c h e s s b o a r d ( a t m o s t o n e c o i n o n o n e s q u a r e ) . W h e n i t i s

    a p l a y e r ` s t u r n h e m u s t c h o o s e o n e o f t h e s e c o i n s t o r e m o v e a n d i n h i s m o v e h e c a n a l s o

    r e m o v e o r a d d a n y c o i n s i n t h a t r o w t h a t a r e l e f t o f t h e r e m o v e d o n e . I f s o m e o n e i s u n a b l e

    t o m o v e h e l o s e s .

    F i n d i n g a w i n n i n g s t r a t e g y o f t h e g a m e i s o f t e n a b o u t n d i n g a n i n v a r i a n t

    w h i c h d i v i d e s p o s i t i o n s t o w i n n i n g a n d l o s i n g o n e s .

    T h e o r e m 2 . 2 . I n t h e g a m e C h e s s b o a r d N i m l o s i n g p o s i t i o n s a r e a l l w i t h a n e v e n n u m b e r

    o f c o i n s i n e v e r y c o l u m n o f t h e c h e s s b o a r d .

    P r o o f . W e c a n p r o v e t h a t b y s e e i n g t h a t f r o m e v e r y s u c h p o s i t i o n i t i s p o s s i b l e t o m o v e

    o n l y t o t h e p o s i t i o n s w i t h a t l e a s t o n e o d d c o l u m n ( i t i s t h e c o l u m n i n w h i c h p l a y e r c h o o s e s

    o n e c o i n t h a t m u s t b e r e m o v e d ) . O n t h e o t h e r h a n d i f t h e r e i s a t l e a s t o n e o d d c o l u m n ,

    p l a y e r c a n c o r r e c t i t b y r e m o v i n g t h e c o i n f r o m t h e m o s t r i g h t o d d c o l u m n a n d t h e n h e c a n

    c h a n g e p a r i t y i n a l l o t h e r c o l u m n s t o t h e l e f t a s h e w a n t s . T h e t e r m i n a l p o s i t i o n ( e m p t y

    c h e s s b o a r d ) h a s a l l e v e n c o l u m n s , s o a p l a y e r w h o i s m o v i n g t o a l l - e v e n - c o l u m n s p o s i t i o n s

    w i l l a l w a y s b e a b l e t o m o v e .

    R e m a r k 2 . 1 . E v e r y r o w o f t h e c h e s s b o a r d i s e q u i v a l e n t t o t h e o n e p i l e o f t h e G a m e o f N i m .

    T h e s i z e o f t h e p i l e i s e n c o d e d i n a b i n a r y s y s t e m b y t h e p o s i t i o n o f c o i n s o n c h e s s b o a r d s

    ( t h e m o s t l e f t c o l u m n i s 20

    , t h e n 21

    ,22

    , . . . ) .

    C o r o l l a r y 2 . 3 . P o s i t i o n o f t h e G a m e o f N i m w i t h p i l e s p1 , p2 , . . . pn i s l o s i n g i f a n d o n l y i f p1 p2 . . . pn = 0, w h e r e i s o p e r a t i o n x o r .

    E x a m p l e 2 . 4 . P o s i t i o n

    (1, 2, 3)i s l o s i n g b e c a u s e

    1 2 3 = (1)2 (10)2 (11)2 = 0.

    E x a m p l e 2 . 5 . P o s i t i o n

    (7, 4, 1)i s w i n n i n g b e c a u s e

    7 4 1 = (111)2 (100)2 (01)2 =(10)2 = 2 = 0

    T h e r e a r e m a n y g a m e s t h a t a r e d i r e c t l y b a s e d o n t h e k n o w l e d g e o f t h e G a m e o f N i m .

    T o n d o u t m o r e a b o u t t h e m w e r e c o m m e n d t o l o o k f o r T u r n i n g T u r t l e s , S t a i r c a s e N i m ,

    N i m b l e o r N o r t h c o t t ` s G a m e .

    8

  • 8/7/2019 Composite Mathematical Games

    9/37

    3 K n o w n w a y s o f a d d i n g i m p a r t i a l g a m e s

    I n t h i s c h a p t e r w e w i l l g e t t h r o u g h m a n y w a y s o f a d d i n g m a t h e m a t i c a l g a m e s t o g e t h e r . I t

    i s a n e s s e n t i a l p a r t o f s t u d y i n g m a t h e m a t i c a l g a m e s , b e c a u s e i t a l l o w s u s t o s o l v e a m u c h

    b i g g e r n u m b e r o f g a m e s .

    B y a d d i n g g a m e s G1 a n d G2 ( w i t h p o s i t i o n s e t s X1 , X2 ) t o g e t h e r w e g e t a n e w g a m e

    G3 . W e c a n l o o k a t t h i s n e w g a m e G3 a s a s t a n d a r d g a m e a n d w e c a n e x a m i n e i t i n t h e s a m e w a y a s

    G1 a n d G2 . B u t i t i s n o t a v e r y g o o d i d e a . T h e n u m b e r o f p o s i t i o n s |X3| i ng a m e

    G3 i s m o s t l y a b o u t |X1||X2|. A n d i n a m o r e g e n e r a l c a s e i f w e h a v e k s u b g a m e s w i t h a p p r o x i m a t e l y

    np o s i t i o n s e a c h , t h e n t h e n u m b e r o f p o s i t i o n s i n t h i s c o m p o s i t e g a m e i s

    a b o u t nk

    . I t i s i n c r e a s i n g e x p o n e n t i a l l y a n d w h i l e t h e s t a n d a r d a l g o r i t h m f o r d e t e r m i n i n g

    W - p o s i t i o n s a n d L - p o s i t i o n s n e e d s t o s e a r c h a l m o s t a l l p o s s i b l e p o s i t i o n s , i t w i l l b e a l m o s t

    i m p o s s i b l e t o n d w i n n i n g s t r a t e g i e s b y u s i n g i t .

    F o r t u n a t e l y , w e c a n d o b e t t e r a n d p r o t f r o m t h e f a c t t h a t w e k n o w b e t t e r a s t r u c t u r e

    o f c o m p o s i t e g a m e . U s u a l l y w e w i l l p r e c o m p u t e s o m e v a l u e s f o r e v e r y s u b g a m e a n d t h e n

    c o m b i n e t h e m i n o r d e r t o n d o u t i f t h e p o s i t i o n i s w i n n i n g o r l o s i n g .

    3 . 1 O r d i n a r y s u m o f g a m e s ( x o r )

    I n t h i s s u b s e c t i o n w e w i l l c o m b i n e g a m e s G1 , G2 , . . . , Gn i n a w a y t h a t t h e p l a y e r w h o s e

    t u r n i t i s m u s t c h o o s e o n e o f t h e g a m e s a n d m a k e a m o v e i n i t . A p l a y e r w h o i s n o t a b l e

    t o m o v e i n a l l t h e g a m e s l o s e s . T h i s c o m b i n a t i o n i s c a l l e d o r d i n a r y s u m a n d w e c a n w r i t e

    G = G1 G2 . . . Gn .F i r s t w e w i l l i n t r o d u c e S p r a g u e - G r u n d y f u n c t i o n g t h a t w i l l a s s i g n v a l u e s t o a l l p o s i t i o n s

    o f a l l s u b g a m e s .

    D e n i t i o n 3 . 1 . T h e S p r a g u e - G r u n d y f u n c t i o n o f a g a m e G ( X, f) i s a f u n c t i o n g : X Z+0 s u c h t h a t

    g(x) = min(n 0 : n = g(y) for y f(x))

    I n w o r d s , t h e S p r a g u e - G r u n d y f u n c t i o n i s r e c u r s i v e l y d e n e d a n d i t g i v e s t o t h e p o s i t i o n

    t h e s m a l l e s t n o n - n e g a t i v e i n t e g e r v a l u e t h a t i s n o t f o u n d a m o n g a l l f o l l o w i n g p o s s i b l e

    p o s i t i o n s t o w h i c h p l a y e r c a n m o v e . A f t e r a s s i g n i n g g r u n d y v a l u e s t o a l l p o s i t i o n s w e c a n

    s e e t h a t x

    i s L - p o s i t i o n i f a n d o n l y i f g(x) = 0

    . I t f o l l o w s f r o m t h e s e p o s i t i o n ` s p r o p e r t i e s :

    1 . A l l t e r m i n a l p o s i t i o n s a r e L - p o s i t i o n s a n d a l l h a v e g(x) = 0

    .

    2 . I f a t p o s i t i o n x

    w e h a v e g(x) > 0

    t h e n t h e r e i s a t l e a s t o n e f o l l o w i n g p o s i t i o n y

    w i t h

    g(y) = 0.

    3 . I f a t p o s i t i o n x

    w e h a v e g(x) = 0

    t h e n i t i s n o t p o s s i b l e t o m o v e t o p o s i t i o n y

    w i t h

    g(y) = 0.

    E x a m p l e 3 . 1 . G r u n d y n u m b e r s f o r L i m i t e d N i m G a m e w i t h

    11c o i n s a n d s u b s t r a c t i o n

    s e tS = {1, 3, 4}

    :

    9

  • 8/7/2019 Composite Mathematical Games

    10/37

    n 0 1 2 3 4 5 6 7 8 9 1 0 1 1

    g ( n ) 0 1 0 1 2 3 2 0 1 0 1 2

    p o s i t i o n L W L W W W W L W L W W

    G r u n d y n u m b e r s g i v e u s m u c h m o r e i n f o r m a t i o n a b o u t t h e g a m e t h a n w h e t h e r a p o s i -

    t i o n i s w i n n i n g o r l o s i n g . T h e y a l l o w u s t o n d q u i c k l y t h e o r d i n a r y s u m o f m o r e g a m e s .

    I n t h i s s u m e v e r y p o s i t i o n x

    i n a g a m e i s e q u i v a l e n t t o o n e p i l e i n t h e G a m e o f N i m o f s i z e

    k, w h e r e

    g(x) = k. W e k n o w h o w t o p l a y t h e G a m e o f N i m s o w e w i l l b e a b l e t o u s e i t t o

    p l a y a n y o r d i n a r y s u m o f a n y g a m e s .

    T h e o r e m 3 . 1 . G i v e n g a m e G(X, f) t h a t i s t h e o r d i n a r y s u m o f n g a m e s G1(X1, f1),G2(X2, f2) , . . . Gn(Xn, fn). P o s i t i o n x = [x1, x2, . . . xn] i s l o s i n g i f a n d o n l y i f g(x1) g(x

    2)

    . . .

    g(xn) = 0 w h e r e x

    X, xi

    Xi a n d

    i s o p e r a t i o n x o r .

    P r o o f . T h e c o m b i n a t i o n o f

    np i l e s i n t h e G a m e o f N i m i s t h e s a m e a s r u l e s f o r a d d i n g

    ng a m e s i n t h e o r d i n a r y w a y . T h e r e f o r e i t i s e n o u g h t o p r o v e t h a t p o s i t i o n

    xi Xi w i t h g(xi) = k i s e q u i v a l e n t t o t h e p i l e i n t h e G a m e o f N i m o f s i z e k .

    I n t h e G a m e o f N i m i f t h e r e i s a p i l e o f s i z e k > 0

    ( i fk = 0

    i t i s n o t p o s s i b l e t o

    m o v e ) t h e n a p l a y e r i s a b l e t o m o v e t o a n y s m a l l e r s i z e u < k

    . I n g a m e Gi w e a r e n o w i n

    p o s i t i o n xi w i t h g(x) = k a n d w h i l e u < k t h e r e m u s t b e f o l l o w i n g p o s i t i o n y w i t h g(y) = u

    ( o t h e r w i s e g(xi) w o u l d b e a t m o s t u ) . S o t h e e q u i v a l e n t m o v e t o t h e s m a l l e r p i l e i n t h e

    G a m e o f N i m o f s i z e u

    i s t o m o v e i n Gi t o p o s i t i o n y .

    I n G a m e Gi a t p o s i t i o n xi w i t h g(xi) = k w e w i l l c o n s i d e r o n l y m o v e s t o f o l l o w i n g

    p o s i t i o n s

    yw h e r e

    g(y) < k. W e c a n d o t h a t b e c a u s e t h e r e i s n o f o l l o w i n g p o s i t i o n o f

    xw i t h

    g(y) = k( o t h e r w i s e

    g(x) = k) a n d i f p l a y e r m o v e s t o p o s i t i o n

    yw i t h

    g(y) > kh i s o p p o n e n t c a n m o v e b a c k t o a n o t h e r p o s i t i o n o f s i z e

    k. I f p l a y e r m o v e s t o p o s i t i o n

    yw i t h

    g(y) < kt h e n w e c a n a l s o d e c r e a s e t h e s i z e o f t h e c o r r e s p o n d i n g p i l e i n t h e G a m e o f

    N i m .

    N o t e 3 . 1 . O p e r a t i o n

    o n g a m e s i s a s s o c i a t i v e , c o m m u t a t i v e a n d

    g(G1 G2) = g(G1) g(G2) .

    3 . 2 U n i o n o f g a m e s ( o r )

    I n t h i s s u b s e c t i o n w e w i l l c o m b i n e g a m e s G1 , G2 , . . . , Gn i n a w a y t h a t t h e p l a y e r w h o s e t u r n i t i s m u s t c h o o s e a t l e a s t o n e o f t h e s e g a m e s a n d m a k e o n e m o v e i n e v e r y c h o s e n o n e .

    A p l a y e r w h o i s n o t a b l e t o m o v e l o s e s . T h i s c o m b i n a t i o n i s c a l l e d u n i o n o f g a m e s a n d w e

    c a n w r i t e i t a s G = G1 G2 . . . Gn .

    R u l e s 3 . 1 ( G a m e o f Q u e e n s )

    . G a m e o f Q u e e n s i s p l a y e d o n a n n n c h e s s b o a r d 2 . A tt h e b e g i n n i n g t h e r e a r e s o m e q u e e n s a t s o m e s q u a r e s o n t h e c h e s s b o a r d ( t h e r e c a n b e m o r e

    2

    E v e r y t h i n g i n t h i s c h a p t e r w o r k s o f c o u r s e f o r a l l i m p a r t i a l g a m e s . W e a r e u s i n g b o a r d o n e s o n l y

    b e c a u s e i t i s m u c h m o r e s i m p l e t o s h o w n u m b e r s a t p o s i t i o n s o n a c h e s s b o a r d t h a n h a v i n g a c o m p l i c a t e d

    g a m e t r e e o f a n a r b i t r a r y g a m e .

    1 0

  • 8/7/2019 Composite Mathematical Games

    11/37

    q u e e n s o n o n e s q u a r e ) . W h e n i t i s p l a y e r ` s t u r n h e m u s t c h o o s e a t l e a s t o n e q u e e n a n d

    m o v e w i t h h e r i n w e s t , n o r t h o r n o r t h - w e s t d i r e c t i o n .

    F i r s t w e c a n n o t i c e t h a t i t w i l l b e t h e s a m e s i t u a t i o n i f e v e r y q u e e n h a s h e r o w n

    c h e s s b o a r d . A f t e r t h a t i t i s o b v i o u s t h a t G a m e o f Q u e e n s i s a u n i o n o f g a m e s w i t h o n l y

    o n e q u e e n o n e a c h c h e s s b o a r d . F o l l o w i n g t h e o r e m s h o w s u s s o l u t i o n .

    T h e o r e m 3 . 2 . G i v e n g a m e G(X, f) t h a t i s u n i o n o f n g a m e s G1(X1, f1) , G2(X2, f2),. . . Gn(Xn, fn) . P o s i t i o n x = [x1, x2, . . . xn] i s l o s i n g i f a n d o n l y i f i g(xi) = 0 w h e r e x X, xi Xi .

    P r o o f . T e r m i n a l p o s i t i o n i s L - p o s i t i o n . A t p o s i t i o n

    yw h i c h h a s

    g(y) = 0w e c a n m o v e o n l y

    t o p o s i t i o n s w i t h n o n - z e r o g r u n d y n u m b e r s . T h e r e f o r e i f i g(xi) = 0 a n d w h i l e a p l a y e r m u s t m o v e a t l e a s t i n o n e s u b g a m e h e w i l l m o v e t o a n e w p o s i t i o n w h e r e a t l e a s t o n e o f

    h e r s u b g a m e s w i l l h a v e g(xk) = 0.O n t h e o t h e r h a n d i f t h e r e i s a t l e a s t o n e s u b g a m e w i t h a p o s i t i o n i n w h i c h t h e g r u n d y

    n u m b e r i s n o n - z e r o , t h e p l a y e r c a n c h o o s e a l l s u b g a m e s f o r w h i c h g(xi) = 0 a n d m o v e i n

    t h e m t o g(xi) = 0 .

    01 2 3 4 5 6 7

    1 20

    4 5 3 7 8

    20

    1 5 3 4 8 6

    3 4 5 6 2 0

    1 9

    4 5 3 2 7 6 9 0

    5 3 40

    6 8 1 0 1

    6 7 8 1 9 1 0 3 4

    7 8 6 9 0

    1 4 5

    F i g u r e 2 : G r u n d y n u m b e r s f o r 8 8 G a m e o f Q u e e n s

    T o s o l v e i n s t a n c e s o f G a m e o f Q u e e n s , r s t w e n e e d t o p r e c o m p u t e g r u n d y n u m b e r s a s

    i n F i g u r e 2 . I f a l l q u e e n s a r e a t s q u a r e s w i t h g r u n d y n u m b e r 0

    t h e n t h e p l a y e r w h o s e t u r n

    i t i s w i l l l o s e o t h e r w i s e h e c a n w i n b y m o v i n g a l l o f t h e m t o 0

    p o s i t i o n s .

    3 . 3 S e l e c t i v e c o m p o u n d ( a l m o s t o r )

    I n t h i s s u b s e c t i o n w e w i l l c o m b i n e g a m e s G1 , G2 , . . . , Gn i n a s l i g h t l y d i e r e n t w a y f r o m o n e u s e d i n u n i o n . T h e p l a y e r w h o s e t u r n i t i s m u s t c h o o s e a t l e a s t o n e o f t h e s e s u b g a m e s ,

    b u t h e c a n n o t c h o o s e a l l o f t h e m a n d t h e n m a k e o n e m o v e i n e v e r y c h o s e n o n e . A p l a y e r

    w h o i s n o t a b l e t o m o v e l o s e s . T h i s c o m b i n a t i o n i s c a l l e d s e l e c t i v e c o m p o u n d o f g a m e s a n d

    w e c a n w r i t e i t a s G = G1 G2 . . . Gn .

    E x a m p l e 3 . 2 . A n e x a m p l e o f s u c h a g a m e i s a s l i g h t l y c h a n g e d v a r i a t i o n o f G a m e o f

    Q u e e n s , w h e r e a p l a y e r c a n n o t c h o o s e a l l t h e q u e e n s t o m o v e .

    1 1

  • 8/7/2019 Composite Mathematical Games

    12/37

    T h e o r e m 3 . 3 . G i v e n g a m e G(X, f) t h a t i s s e l e c t i v e c o m p o u n d o f n g a m e s G1(X1, f1),G2(X2, f2) , . . . Gn(Xn, fn). P o s i t i o n x = [x1, x2, . . . xn] i s l o s i n g i f a n d o n l y i f g(x1) =

    g(x2) = . . . = g(xn)w h e r e

    x X,

    xi Xi.

    P r o o f . T e r m i n a l p o s i t i o n i s L - p o s i t i o n , b e c a u s e i g(xi) = 0. I n L - p o s i t i o n i g(xi) = ua n d w h i l e a p l a y e r c a n n o t m o v e i n a l l s u b g a m e s , a f t e r m o v e

    xk g(xk) = u. B u t w h i l e a p l a y e r h a s t o m o v e a t l e a s t i n o n e s u b g a m e t h e r e w i l l b e a t l e a s t o n e p o s i t i o n w i t h

    g(xl) = u .L e t

    m = min(g(xi)) t h r o u g h a l l p o s i t i o n s xi . I f p l a y e r i s i n W - p o s i t i o n t h e n a l l s u b - g a m e s c a n n o t h a v e t h e s a m e g r u n d y n u m b e r . T h e r e f o r e a p l a y e r c a n a l w a y s m a k e a m o v e

    b y d e c r e a s i n g g(xi) t o m i n a l l p o s i t i o n s xi w i t h g(xi) > m .

    T h e o r e m 3 . 3 s h o w s u s h o w t o p l a y t h e g a m e f r o m E x a m p l e 3 . 2 . I f a l l q u e e n s a r e a t

    s q u a r e s w i t h t h e s a m e g r u n d y n u m b e r s ( w e c a n u s e g r u n d y n u m b e r s f r o m F i g u r e 2 ) i t i s

    L - p o s i t i o n . O t h e r w i s e a p l a y e r c a n m o v e a l l o f t h e m t o t h e s a m e g r u n d y n u m b e r ( w h i c h

    i s t h e m i n i m u m a m o n g g r u n d y n u m b e r s o f c u r r e n t p o s i t i o n s i n s u b g a m e s ) .

    3 . 4 C o n j u n c t i v e c o m p o u n d ( a n d )

    I n t h i s s u b s e c t i o n w e w i l l c o m b i n e g a m e s G1 , G2 , . . . , Gn i n a w a y t h a t t h e p l a y e r w h o s e

    t u r n i t i s m u s t m a k e a m o v e i n e v e r y s u b g a m e . A p l a y e r w h o i s n o t a b l e t o m o v e l o s e s .

    T h i s c o m b i n a t i o n i s c a l l e d c o n j u n c t i v e c o m p o u n d o f g a m e s a n d w e c a n w r i t e i t a s G =

    G1 G2 . . . Gn .W e w i l l s t a r t w i t h a n e x a m p l e g a m e u s e d a l s o i n t h e 9 t h c h a p t e r o f [ W w 0 1 ] . T h e n a m e

    o f t h e g a m e i s A l l t h e K i n g ` s h o r s e s a n d i t i s v e r y s i m i l a r t o G a m e o f Q u e e n s .

    2 1

    3

    H

    4

    F i g u r e 3 : P o s s i b l e m o v e s ( j u m p s ) f o r h o r s e i n A l l t h e K i n g ` s h o r s e s g a m e .

    R u l e s 3 . 2 ( A l l t h e K i n g ` s h o r s e s ) . G a m e i s p l a y e d o n a n n n o r q u a r t e r - i n n i t e c h e s s -

    b o a r d . A t t h e b e g i n n i n g t h e r e a r e s o m e h o r s e s a t s o m e s q u a r e s o n t h e c h e s s b o a r d . T h e r e

    c a n b e m o r e t h a n o n e h o r s e a t o n e s q u a r e . W h e n i t i s a p l a y e r ` s t u r n h e m u s t m o v e w i t h

    a l l t h e h o r s e s . A p l a y e r w h o c a n n o t m o v e l o s e s . H o r s e s m o v e ( j u m p ) l i k e k n i g h t s i n c h e s s

    b u t a t m o s t o n l y t o f o u r p o s i t i o n s

    3

    w i t h a l o w e r s u m o f r o w a n d c o l u m n c o o r d i n a t e s .

    3

    a s i t i s s h o w n i n F i g u r e 3

    1 2

  • 8/7/2019 Composite Mathematical Games

    13/37

    W e c a n l o o k a t t h i s g a m e a s i t i s a c o n j u n c t i v e c o m p o u n d o f n

    s u b g a m e s p l a y e d o n n

    c h e s s b o a r d s w i t h e x a c t l y o n e h o r s e o n e v e r y c h e s s b o a r d . I n t u r n a p l a y e r m u s t m o v e i n

    e v e r y s u b g a m e . A s s u m e f o r a w h i l e t h a t w e h a v e o n l y o n e c h e s s b o a r d w i t h o n l y o n e h o r s e .

    W e c a n u s e a s t a n d a r d a l g o r i t h m f o r d i v i d i n g p o s i t i o n s t o W - p o s i t i o n s a n d L - p o s i t i o n s .

    T h e r e s u l t o f t h i s a l g o r i t h m f o r n n

    b o a r d i s s h o w n i n F i g u r e 4 .

    L L W W L L W W

    L L W W L L W W

    W W W W W W W W

    W W W W W W W W

    L L W W L L W W

    L L W W L L W W

    W W W W W W W W

    W W W W W W W L

    F i g u r e 4 : A l l t h e K i n g ` s h o r s e s o n 8 8 c h e s s b o a r d w i t h o n l y o n e h o r s e

    N o t e 3 . 2 . W h e n i t i s a p l a y e r ` s t u r n h e m u s t p l a y i n a l l s u b g a m e s , t h e r e f o r e i f h e c a n

    f o r c e a w i n i n a l l o f t h e m h e w i l l w i n t h i s g a m e , b e c a u s e h e w i l l a l w a y s b e a b l e t o m o v e .

    E x c e p t t h e p r e v i o u s s i m p l e c a s e i t c a n h a p p e n t h a t i n s o m e s u b g a m e s t h e r e i s i n

    w i n n i n g p o s i t i o n F i r s t a n d i n t h e o t h e r s S e c o n d p l a y e r . W i n n i n g s u b g a m e s a r e g o o d f o r

    b o t h p l a y e r s , b e c a u s e t h e y c a n n o t l o s e b e c a u s e o f t h e m . T h e r e f o r e b o t h p l a y e r s w i l l w i n

    a l l t h e i r s u b g a m e s t h e y c a n . O n l y l o s i n g s u b g a m e s a r e d a n g e r o u s f o r t h e m a n d w h i l e r u l e s

    s a y " P l a y e r n o t a b l e t o m o v e l o s e s " , t h e w i n n i n g s t r a t e g y i s f o r b o t h o f t h e m t o w i n q u i c k l y

    a n d l o s e a s s l o w l y a s p o s s i b l e .

    D e n i t i o n 3 . 2 . R e m o t e n e s s f u n c t i o n r t e l l s u s h o w m a n y m o v e s t h e g a m e w i l l l a s t i f a p l a y e r w h o c a n f o r c e a w i n w i l l t r y t o w i n a s s o o n a s p o s s i b l e a n d t h e l o s i n g p l a y e r w i l l t r y

    t o l o s e a s s l o w l y a s p o s s i b l e .

    R e m a r k 3 . 1 . L - p o s i t i o n s h a v e e v e n r e m o t e n e s s a n d W - p o s i t i o n s h a v e o d d r e m o t e n e s s .

    T h e o r e m 3 . 4 . R e m o t e n e s s v a l u e o f p o s i t i o n x:

    1 . r(x) = 0 i f x i s t e r m i n a l p o s i t i o n .

    2 . r(x) = 1+ l e a s t e v e n n u m b e r r(k), k f(x) i f s u c h e x i s t s .

    3 .r(x) = 1+

    g r e a t e s t o d d n u m b e r r(k)

    ,k f(x) i f t h e r e i s n o e v e n n u m b e r r(k) .

    P r o o f . 1 . I f p o s i t i o n

    xi s t e r m i n a l p o s i t i o n i t i s o b v i o u s .

    2 . I f w e h a v e t h e o p t i o n t o m o v e t o a p o s i t i o n w i t h e v e n r e m o t e n e s s ( l o s i n g p o s i t i o n )

    w e a r e i n a w i n n i n g p o s i t i o n . W e w a n t t o w i n a s s o o n a s p o s s i b l e s o w e w i l l c h o o s e

    t h e l o s i n g p o s i t i o n k f(x)

    w i t h s m a l l e s t r e m o t e n e s s a n d m o v e t o i t .

    1 3

  • 8/7/2019 Composite Mathematical Games

    14/37

    3 . W e c a n n o t m o v e t o a n e v e n r e m o t e ( l o s i n g ) p o s i t i o n , t h e r e f o r e w e a r e i n a l o s i n g

    p o s i t i o n . W e w a n t t o p l a y a s l o n g a s p o s s i b l e s o w e w i l l c h o o s e t h e p o s i t i o n k f(x)

    w i t h t h e h i g h e s t r e m o t e n e s s a n d m o v e t o i t .

    0 0 1 1 2 2 3 3

    0 0 1 1 2 2 3 3

    1 1 1 1 3 3 3 3

    1 1 1 3 3 3 3 5

    2 2 3 3 4 4 5 5

    2 2 3 3 4 4 5 5

    3 3 3 3 5 5 5 5

    3 3 3 5 5 5 5 6

    F i g u r e 5 : R e m o t e n e s s v a l u e s f o r A l l t h e K i n g ` s h o r s e s o n 8 8

    c h e s s b o a r d

    T h e o r e m 3 . 5 . G i v e n g a m e G(X, f) t h a t i s c o n j u n c t i v e c o m p o u n d o f n g a m e s G1(X1, f1),G2(X2, f2) , . . . Gn(Xn, fn) . P o s i t i o n x = [x1, x2, . . . xn] i s l o s i n g i f a n d o n l y i f min(r(x1),r(x2) , . . . r(xn)) i s e v e n , w h e r e x X, xi Xi .

    P r o o f . F r o m t h e d e n i t i o n o f c o n j u n c t i v e c o m p o u n d w e h a v e t h a t t h e r s t n i s h e d g a m e

    d e t e r m i n e s t h e w i n n e r . F i r s t n i s h e d g a m e w i l l b e t h e g a m e w i t h t h e l e a s t r e m o t e n e s s , s o

    i f t h i s r e m o t e n e s s i s e v e n F i r s t w i l l l o s e t h i s g a m e a n d t h e r e f o r e h e w i l l l o s e c o n j u n c t i v e

    c o m p o u n d , a s w e l l .

    C o r o l l a r y 3 . 6 . R e m o t e n e s s v a l u e o f p o s i t i o n x = [x1, x2, . . . xn] , r(x) = min(r(x1) , r(x2),. . . r(xn)) w h e r e p o s i t i o n x i s p o s i t i o n o f c o n j u n c t i v e c o m p o u n d o f p o s i t i o n s x1 , x2 , . . . xn .

    N o t e 3 . 3 . O p e r a t i o n o n g a m e s i s a s s o c i a t i v e , c o m m u t a t i v e a n d r(G1G2) = min(r(G1) ,

    r(G2)) .

    3 . 5 C o n t i n u e d c o n j u n c t i v e c o m p o u n d ( a l s o )

    I n t h i s s u b s e c t i o n w e w i l l c o m b i n e g a m e s G1 , G2 , . . . , Gn i n a w a y t h a t t h e p l a y e r w h o s e

    t u r n i t i s m u s t m a k e a m o v e i n e v e r y s u b g a m e h e c a n a n d t h e g a m e e n d s a n d a p l a y e r

    l o s e s o n l y i f h e c a n n o t m o v e a n y w h e r e . T h i s c o m b i n a t i o n i s c a l l e d c o n t i n u e d c o n j u n c t i v e

    c o m p o u n d o f g a m e s a n d w e c a n w r i t e i t a s G = G1 G2 . . . Gn .

    E x a m p l e 3 . 3 . C o n s i d e r A l l t h e K i n g ` s h o r s e s g a m e w i t h s l i g h t l y c h a n g e d r u l e s w h e r e a

    p l a y e r m u s t m o v e o n l y w i t h t h e h o r s e s h e c a n . A n d h e l o s e s o n l y i f h e c a n n o t m o v e w i t h

    a l l .

    1 4

  • 8/7/2019 Composite Mathematical Games

    15/37

    T h e w i n n i n g s t r a t e g y i s a p a r o d y t o o n e u s e d i n c o n j u n c t i v e c o m p o u n d o f g a m e s . I t i s

    t h e s a m e f o r p l a y e r s t h a t o n l y s u b g a m e s t h e y w i l l l o s e a r e d a n g e r o u s . B u t i n t h i s c a s e i t

    d o e s n o t m a t t e r i f p l a y e r l o s e s s u b g a m e i f t h e r e a r e o t h e r n o t n i s h e d s u b g a m e s . T h e r e f o r e

    a p l a y e r w i l l t r y t o n i s h l o s i n g s u b g a m e s a s s o o n a s p o s s i b l e a n d p l a y w i n n i n g s u b g a m e s

    a s l o n g a s p o s s i b l e . T h i s t i m e t h e w i n n e r i s d e t e r m i n e d b y t h e l a s t n i s h e d s u b g a m e .

    D e n i t i o n 3 . 3 . S u s p e n s e f u n c t i o n s t e l l s u s h o w m a n y m o v e s a g a m e w i l l l a s t i f p l a y e r w h o c a n n o t f o r c e w i n w i l l t r y t o l o s e a s s o o n a s p o s s i b l e a n d w i n n i n g p l a y e r w i l l t r y t o p l a y

    a s l o n g a s p o s s i b l e .

    R e m a r k 3 . 2 . L - p o s i t i o n s h a v e e v e n s u s p e n s e n u m b e r a n d W - p o s i t i o n s h a v e o d d s u s p e n s e

    n u m b e r .

    T h e o r e m 3 . 7 . S u s p e n s e n u m b e r o f p o s i t i o n x :

    1 . s(x) = 0 i f x i s t e r m i n a l p o s i t i o n .

    2 .s(x) = 1+

    g r e a t e s t e v e n n u m b e r s(k)

    ,k f(x) i f s u c h e x i s t s .

    3 . s(x) = 1+ l e a s t o d d n u m b e r s(k), k f(x) i f t h e r e i s n o e v e n n u m b e r s(k).

    P r o o f . A l m o s t t h e s a m e a s p r o o f o f T h e o r e m 3 . 4 .

    0 0 1 1 2 2 3 3

    0 0 1 1 2 2 3 3

    1 1 1 3 3 3 3 3

    1 1 3 3 3 3 5 5

    2 2 3 3 2 4 5 5

    2 2 3 3 4 4 5 5

    3 3 3 5 5 5 5 5

    3 3 3 5 5 5 5 6

    F i g u r e 6 : S u s p e n s e n u m b e r s f o r c h a n g e d A l l t h e K i n g ` s h o r s e s o n 8 8 c h e s s b o a r d f r o m

    E x a m p l e 3 . 3

    T h e o r e m 3 . 8 . G i v e n g a m e G(X, f) t h a t i s c o n t i n u e d c o n j u n c t i v e c o m p o u n d o f n g a m e s G1(X1, f1) , G2(X2, f2), . . . Gn(Xn, fn) . P o s i t i o n x = [x1, x2, . . . xn] i s l o s i n g i f a n d o n l y i f max(s(x1), s(x2), . . . s(xn)) i s e v e n , w h e r e x X, xi Xi .

    P r o o f . A l m o s t t h e s a m e a s p r o o f o f T h e o r e m 3 . 5 .

    C o r o l l a r y 3 . 9 . S u s p e n s e n u m b e r o f p o s i t i o n x = [x1, x2, . . . xn] , s(x) = max(s(x1), s(x2),. . . s(xn)) w h e r e p o s i t i o n x i s p o s i t i o n o f c o n t i n u e d c o n j u n c t i v e c o m p o u n d o f p o s i t i o n s x1 ,x2 , . . . xn .

    N o t e 3 . 4 . O p e r a t i o n o n g a m e s i s a s s o c i a t i v e , c o m m u t a t i v e a n d s(G1G2) = max(s(G1),s(G2)) .

    1 5

  • 8/7/2019 Composite Mathematical Games

    16/37

    4 T h e D o t s a n d B o x e s g a m e

    T h e D o t s a n d B o x e s i s a p e n a n d p e n c i l g a m e f o r t w o p l a y e r s . I t s t a r t s w i t h a n e m p t y

    g r i d o f d o t s . P l a y e r s a l t e r n a t i v e l y m o v e b y a d d i n g a v e r t i c a l o r h o r i z o n t a l l i n e b e t w e e n

    t w o u n j o i n e d a d j a c e n t d o t s . I f a p l a y e r c o m p l e t e s t h e f o u r t h s i d e o f t h e b o x h e e a r n s o n e

    p o i n t a n d t a k e s o n e m o r e t u r n . T h e g a m e e n d s w h e n t h e r e i s n o a d d i t i o n a l m o v e l e f t a n d

    t h e p l a y e r w i t h m o r e p o i n t s i s t h e w i n n e r .

    A l o t o f i n f o r m a t i o n a b o u t t h e g a m e a n d s t r a t e g i e s c a n b e f o u n d i n [ B e 0 0 ] . F i g u r e 7

    s h o w s e x a m p l e o f s i m p l e g a m e o n 3 3

    b o a r d w h e r e F i r s t p l a y e r w o n 3

    :1

    .

    Firstsmove Secondsmove Firstsmove

    Secondsmove Firstsmove Secondsmove

    Firstsmove Secondsmove

    S

    Firstsmove

    S F

    F F

    F i g u r e 7 : E x a m p l e o f 3 3 D o t s a n d B o x e s g a m e

    4 . 1 D e g e n e r a t e v a r i a t i o n

    I n t h i s c h a p t e r w e w i l l s t u d y a d e g e n e r a t e v a r i a t i o n o f t h e D o t s a n d B o x e s g a m e . I t i s

    s i m i l a r t o t h e o r i g i n a l o n e w i t h t h e r u l e t h a t i t e n d s a f t e r s o m e o n e c o m p l e t e s t h e r s t b o x

    a n d t h e p l a y e r w h o m a d e t h a t b o x w i n s .

    T h e r e a s o n w h y w e s t u d y a d e g e n e r a t e v a r i a t i o n i s t h a t i t i s c l o s e l y r e l a t e d t o t h e

    o r i g i n a l D o t s a n d B o x e s . D o t s a n d B o x e s i s a g a m e t h a t c a n b e p l a y e d a t m o r e l e v e l s a n d

    p l a y e r s w h o k n o w h o w t o p l a y i t a t a h i g h e r l e v e l t h a n t h e i r o p p o n e n t s c a n u s u a l l y w i n

    i t e a s i l y . A t t h e s e h i g h e r l e v e l s i t i s m o s t l y a b o u t t a k i n g c o n t r o l o f t h e g a m e . U s u a l l y i f

    1 6

  • 8/7/2019 Composite Mathematical Games

    17/37

    t h e r e a r e s u c i e n t l y m a n y c h a i n s o f l e n g t h a t l e a s t 3

    a n d l o o p s o f l e n g t h a t l e a s t 4

    , i t o f t e n

    h a p p e n s t h a t a p l a y e r c a n n o t h o p e t o w i n u n l e s s h e c a p t u r e s t h e n e x t b o x . A l t h o u g h t h a t

    i s n o t a l w a y s s u c i e n t , i t s n e c e s s i t y f o r c e s a p l a y e r t o m a k e m o v e s c o n s i s t e n t w i t h w i n n i n g

    m o v e s i n t h e d e g e n e r a t e g a m e . S o i t c a n b e a v e r y s t r o n g c o n s t r a i n t a n d t h i s d e g e n e r a t e

    g a m e c a n b e v e r y h e l p f u l i n n d i n g a w i n n i n g m o v e i n t h e o r i g i n a l v e r s i o n ( o r p r o v i n g t h a t

    n o s u c h m o v e e x i s t s ) .

    4 . 2 S o l u t i o n f o r s t a r t i n g p o s i t i o n s o f d e g e n e r a t e v a r i a t i o n

    D e n i t i o n 4 . 1 . D e g e n e r a t e mn D o t s a n d B o x e s g a m e i s p l a y e d o n t h e b o a r d t h a t c o n s i s t s o f

    mr o w s a n d

    nc o l u m n s o f d o t s w h e r e

    m, n 2 .

    F i r s t w e c a n c o n s i d e r 2 n d e g e n e r a t e g a m e s . A l l v e r t i c a l m o v e s e x c e p t t h e m o s t l e f t

    a n d t h e m o s t r i g h t d i v i d e s t h e p l a y i n g b o a r d i n t o t w o p a r t s . A n i d e a t h a t c o u l d c o m e t o

    a n e x p e r i e n c e d r e a d e r s m i n d c o u l d b e t o u s e s y m m e t r y , b e c a u s e i t i s o n e o f t h e s t r o n g e s t

    w e a p o n s ( a l t h o u g h s o m e t i m e s h a r d o r i m p o s s i b l e t o u s e ) t h a t i s u s e d i n c o m b i n a t o r i a l

    g a m e t h e o r y .

    N o w i m a g i n e f o r a w h i l e t h a t w e a r e i n a l i t t l e b i t d i e r e n t s i t u a t i o n . F i r s t p l a y e r m a d e

    a v e r t i c a l l i n e t h a t h a s d i v i d e d t h e g a m e i n t o t w o e q u a l p a r t s ( i t i s p o s s i b l e f o r o d d n

    ) .

    N o w w e h a v e t w o i n d e p e n d e n t g a m e s . I f w e u s e o r d i n a r y s u m ( t h a t p l a y e r w h o c a n n o t

    m o v e l o s e s ) f o r t h e s e t w o g a m e s , i t i s a w i n n i n g s i t u a t i o n f o r F i r s t . F o r h i m i t i s e n o u g h t o

    w a i t f o r t h e o p p o n e n t ` s m o v e a n d t h e n j u s t c o p y i t t o a n o t h e r g a m e . S o F i r s t w i l l a l w a y s

    h a v e t h e p o s s i b i l i t y t o m o v e s o h e w i l l w i n s u c h a g a m e .

    N o w g o b a c k t o

    2 nd e g e n e r a t e g a m e . I t i s o n l y a l i t t l e b i t m o r e d i c u l t f o r F i r s t t o

    w i n i f n

    i s o d d . S i m i l a r l y t o t h e p r e v i o u s c a s e h e w i l l s t a r t t h e g a m e b y j o i n i n g t w o d o t s i n

    t h e c e n t e r . S o t h e b o a r d i s d i v i d e d i n t o t w o e q u a l p a r t s ( s u b g a m e s ) . I f s o m e o n e c o m p l e t e s

    t h e b o x i n e i t h e r l e f t o r r i g h t p a r t h e w i l l w i n t h i s g a m e . A f t e r s p l i t t i n g t h e g a m e i n t o t w o

    p a r t s i t i s S e c o n d p l a y e r ` s t u r n . T h e b e s t r e s p o n s e t o e v e r y S e c o n d ` s m o v e i s t o

    c o m p l e t e t h e b o x ( m a k e a w i n n i n g m o v e ) i f p o s s i b l e

    c o p y S e c o n d ` s m o v e i n t o a n o t h e r s u b g a m e ( m a k e a s y m m e t r i c m o v e ) o t h e r w i s e .

    S e c o n d p l a y e r c a n n o t w i n , b e c a u s e w h e n i t i s h i s t u r n l e f t a n d r i g h t s u b g a m e s a r e t h e

    s a m e . S o i f h e h a d t h e p o s s i b i l i t y t o c o m p l e t e a b o x i n o n e o f t h e s u b g a m e s t h e n F i r s t

    w o u l d h a v e t h e s a m e p o s s i b i l i t y i n h i s l a s t m o v e i n a t l e a s t o n e s u b g a m e .

    W e w i l l g e n e r a l i z e t h i s s y m m e t r i c c o n c e p t f o r e v e n n

    a n d a l s o f o r m > 2

    . I t i s q u i t e

    c l e a r t h a t t h i s w o r k s f o r g a m e s w h i c h a r e d i v i d e d b y a s e t o f l i n e s t o t w o e q u a l s u b g a m e s .

    A s w e w i l l s e e f r o m t h e f o l l o w i n g t h e o r e m i t w i l l w o r k a l s o f o r g a m e s w i t h o u t t h i s d e l i m i t i n g

    s e t o f l i n e s .

    T h e o r e m 4 . 1 . I f m + n i s e v e n S e c o n d p l a y e r c a n w i n a l l d e g e n e r a t e m n D o t s a n d B o x e s g a m e s .

    1 7

  • 8/7/2019 Composite Mathematical Games

    18/37

    P r o o f . I f

    m + ni s e v e n t h e r e a r e t w o p o s s i b i l i t i e s . B o t h

    ma n d

    na r e o d d o r b o t h

    ma n d

    na r e e v e n . I n t h e r s t c a s e t h e c e n t e r o f s y m m e t r y o f

    m n b o a r d S i s i n t h e m i d d l e o f t h e c e n t e r b o x a n d i n t h e s e c o n d c a s e i t i s i n t h e c e n t r a l d o t . I n b o t h c a s e s e v e r y l i n e

    ah a s i t s o w n t w i n l i n e

    aw h i c h i s i t s i m a g e i n t h e s y m m e t r y b y

    S. W e c l a i m t h a t i f S e c o n d

    w a n t s t o w i n i t i s e n o u g h f o r h i m t o

    c o m p l e t e t h e b o x ( m a k e a w i n n i n g m o v e ) i f p o s s i b l e

    m a k e a s y m m e t r i c m o v e t o F i r s t ` s m o v e ( S o i f F i r s t a d d e d a l i n e

    aS e c o n d w i l l a d d

    i t s t w i n l i n e a

    ) .

    T o p r o v e t h e t h e o r e m w e w i l l p r o v e t h a t a f t e r S e c o n d ` s m o v e e i t h e r g a m e h a s n i s h e d

    ( s o S e c o n d w o n ) o r e v e r y b o x h a s a t m o s t t w o l i n e s a n d t h e b o a r d i s s y m m e t r i c . A t t h e

    b e g i n n i n g t h i s s t a t e m e n t i s t r u e . F i r s t c a n a d d l i n e

    ai n t h e w a y t h a t e i t h e r o n e b o x w i l l

    h a v e t h r e e l i n e s o r n o t . I n t h e r s t c a s e S e c o n d p l a y e r w i l l c o m p l e t e t h i s b o x a n d w i n t h e

    g a m e . I n t h e s e c o n d c a s e S e c o n d p l a y e r w i l l a d d t w i n l i n e a

    . T h e r e a r e t w o p o s s i b i l i t i e s

    a g a i n . I f a

    a n da

    a r e n o t p a r t o f t h e s a m e b o x t h e n w h i l e t h e b o a r d i s s y m m e t r i c a n d

    a f t e r a d d i n g a

    t h e r e w a s n o b o x w i t h t h r e e l i n e s t h e r e i s n o s u c h b o x a l s o n o w . I f a

    a n da

    a r e p a r t o f t h e s a m e b o x i t m e a n s t h a t S

    i s i n t h e c e n t e r o f t h i s b o x . A f t e r S e c o n d ` s m o v e

    t h e b o a r d i s s y m m e t r i c s o t h i s c e n t e r b o x h a s e i t h e r t w o o r f o u r l i n e s . I f f o u r t h e n S e c o n d

    w o n o t h e r w i s e t h i s b o x h a s o n l y t w o l i n e s .

    T h e o r e m 4 . 2 . I f m + n i s o d d F i r s t p l a y e r c a n w i n a l l d e g e n e r a t e m n D o t s a n d B o x e s g a m e s .

    P r o o f . I f

    m + ni s o d d t h e n e i t h e r

    mi s e v e n a n d

    ni s o d d o r

    mi s o d d a n d

    ni s e v e n . I n

    b o t h c a s e s t h e c e n t e r o f s y m m e t r y o f m n

    b o a r d S

    i s i n t h e c e n t e r o f o n e l i n e l

    . E v e r y

    o t h e r l i n e a

    h a s i t s o w n t w i n l i n e a

    w h i c h i s i t s i m a g e i n s y m m e t r y b y S

    . F i r s t p l a y e r

    c a n f o r c e a w i n b y s t a r t i n g t h e g a m e b y a d d i n g l i n e l

    . A f t e r t h a t w e h a v e t h e s i t u a t i o n i n

    w h i c h t h e b o a r d i s s y m m e t r i c , e v e r y b o x h a s a t m o s t t w o l i n e s a n d f o r e v e r y f r e e l i n e a

    t h e r e i s i t s t w i n l i n e a

    t h a t i s f r e e , t o o . S o w e a r e i n t h e s a m e s i t u a t i o n a s i n t h e s e c o n d

    p a r t o f p r o o f o f T h e o r e m 4 . 1 .

    1 8

  • 8/7/2019 Composite Mathematical Games

    19/37

    5 w - n u m b e r s

    I n t h e p r e v i o u s s e c t i o n w e e x p l a i n e d s o l u t i o n t o e m p t y b o a r d s o f d e g e n e r a t e d D o t s a n d

    B o x e s g a m e . D u r i n g l o o k i n g f o r s t r a t e g i e s f o r a n y o t h e r p o s i t i o n s i n t h i s g a m e w e n o t i c e d

    t h a t i t o f t e n h a p p e n s t h a t t h e w h o l e g a m e i s d i v i d e d i n t o s u b g a m e s l i k e i n F i g u r e 8 .

    F i g u r e 8 : P o s i t i o n i n t h e d e g e n e r a t e d D o t s a n d B o x e s g a m e

    I n F i g u r e 8 w e c a n s e e t h a t t h e b o a r d i s d i v i d e d i n t o t h r e e i n d e p e n d e n t p a r t s b o r d e r e d

    b y l i n e s o r e d g e s o f t h e b o a r d . W h e n i t i s a p l a y e r ` s t u r n h e c a n c h o o s e o n e o f t h e s e

    s u b g a m e s a n d a d d a l i n e i n t o i t . I f h e c r e a t e s a b o x h e w i l l w i n n o t o n l y t h a t p a r t i c u l a r

    s u b g a m e b u t a l s o t h e w h o l e g a m e w h i c h i s a c o m b i n a t i o n o f t h e s e t h r e e p a r t s .

    A f t e r t h a t w e d e c i d e d t o l o o k m o r e d e e p l y i n t o h o w t o p l a y a c o m b i n a t i o n o f g a m e s

    w h e r e t h e r u l e i s t h a t i f s o m e o n e w i n s r s t g a m e h e w i l l w i n t h e w h o l e c o m b i n a t i o n o f

    g a m e s . B e c a u s e o f t h a t w e s t a r t e d t o c a l l t h i s t y p e o f c o m p o u n d g a m e a W T I A g a m e ,

    w h e r e W T I A s t a n d s f o r T h e w i n n e r t a k e s i t a l l

    4

    . I n t h i s s e c t i o n w e w i l l p r o v i d e o u r r e s u l t s .

    D e n i t i o n 5 . 1 . W T I A g a m e G i s a g a m e t h a t i s a c o m b i n a t i o n o f n s u b g a m e s G1, G2, . . . Gn .I f i t i s a p l a y e r ` s m o v e h e c h o o s e s o n e o f t h e s u b g a m e s a n d m a k e s m o v e i n i t . A p l a y e r

    w h o l o s e s o n e o f t h e s u b g a m e s Gi l o s e s t h e w h o l e g a m e G.

    F i r s t o b s e r v a t i o n h o w i t d o e s w o r k w a s d o n e i n t h e p r e v i o u s s e c t i o n . I f w e h a v e a

    W T I A g a m e G t h a t c o n s i s t s o f t h e t w o s a m e s u b g a m e s i t i s a l o s i n g p o s i t i o n . W e c a n

    s i m p l y e x t e n d o u r s t r a t e g y u s e d i n S u b s e c t i o n 4 . 2

    5

    t o s h o w i t .

    I f a W T I A g a m e G c o n s i s t s o f t h e s t a n d a r d G a m e o f N i m s u b g a m e s i t i s n o t a g o o d r e s e a r c h m o d e l f o r u s , b e c a u s e F i r s t p l a y e r c a n e a s i l y t a k e a l l t h e c o i n s f r o m a n y o f t h e

    p i l e s a n d i m m e d i a t e l y w i n . A f t e r s o m e e x p e r i m e n t s w e h a v e f o u n d a g o o d m o d e l g a m e .

    W e n a m e d i t L e v e l N i m a n d i t h a s h e l p e d m e t o n d a s o l u t i o n h o w t o c o m b i n e g a m e s i n

    a W T I A w a y .

    R u l e s 5 . 1 . T h e g a m e o f L e v e l N i m i s p l a y e d w i t h n

    s u p e r p i l e s o f c o i n s . A s u p e r p i l e o f

    c o i n s c o n s i s t s o f s e v e r a l p i l e s o f c o i n s w h i c h a r e l o c a t e d o n t h e e a c h o t h e r . W h e n i t i s a

    4

    m a y b e i t i s a l s o b e c a u s e I l i k e t h a t f a m o u s s o n g

    5

    m a k e w i n n i n g m o v e i f p o s s i b l e o r c o p y o p p o n e n t s m o v e o t h e r w i s e

    1 9

  • 8/7/2019 Composite Mathematical Games

    20/37

    p l a y e r ` s t u r n h e c h o o s e s o n e s u p e r p i l e a n d t a k e s a t l e a s t o n e c o i n f r o m t h e m o s t t o p n o n -

    e m p t y p i l e o f t h i s s u p e r p i l e . A f t e r s o m e o n e t a k e s t h e l a s t c o i n o f t h e s u p e r p i l e a g a m e i s

    n i s h e d a n d t h a t p l a y e r i s d e c l a r e d t h e w i n n e r .

    E x a m p l e 5 . 1 . L e t s h a v e L e v e l N i m w i t h t w o s u p e r p i l e s . T h e r s t s u p e r p i l e h a s p i l e s w i t h

    t h e s i z e s 3

    ,7

    ,2

    a n d t h e s e c o n d s u p e r p i l e c o n s i s t s o f p i l e s 4

    ,6

    . N o w w h e n i t i s a p l a y e r ` s

    t u r n h e i s e i t h e r a b l e t o t a k e a w a y u p t o 2

    c o i n s f r o m t h e r s t s u p e r p i l e o r u p t o 6

    c o i n s

    f r o m t h e s e c o n d s u p e r p i l e . A p l a y e r c a n t a k e c o i n s f r o m l o w e r p i l e s o n l y i f a l l h i g h e r o n e s

    a r e e m p t y .

    N o t i c e t h a t t h e r e a r e s o m e s p e c i a l p o s i t i o n s i n t h e L e v e l N i m . I f o n e o f t h e s u p e r p i l e s

    i s e m p t y t h e n g a m e i s n i s h e d a n d w e w i l l c a l l t h i s p o s i t i o n s u p e r l o s i n g

    ( I f w e a d d a n y

    o t h e r s u p e r p i l e s w e w i l l k e e p b e i n g i n l o s i n g p o s i t i o n ) . A s o p p o s i t e t o t h e m t h e r e a r e

    p o s i t i o n s f r o m w h i c h p l a y e r s c a n w i n i n o n e m o v e . W e w i l l c a l l t h e m s u p e r w i n n i n g

    . A l l

    t h e p o s i t i o n s i n L e v e l N i m w h i c h a r e n o t s u p e r l o s i n g a n d h a v e a t l e a s t o n e s u p e r p i l e w i t h

    o n l y o n e n o n - e m p t y p i l e a r e s u p e r w i n n i n g , b e c a u s e a p l a y e r w h o s e t u r n i t i s c a n w i n b y

    r e m o v i n g a l l t h e c o i n s f r o m t h i s s u p e r p i l e .

    1 . A f t e r d i v i d i n g a l l t h e p o s i t i o n s t o s u p e r l o s i n g , s u p e r w i n n i n g a n d n o r m a l w e c a n s e e

    t h a t i f a t l e a s t o n e s u p e r p i l e h a s o n l y o n e n o n e m p t y p i l e t h e n a g a m e i s i n a s u p e r

    p o s i t i o n e l s e i t i s i n a n o r m a l p o s i t i o n .

    2 . I f w e a r e i n a s u p e r p o s i t i o n w e k n o w h o w t o p l a y . I f w e a r e i n a n o r m a l p o s i t i o n w e

    c a n m o v e t o n o r m a l p o s i t i o n s o r t o s u p e r w i n n i n g o n e s ( N o t t o s u p e r l o s i n g , b e c a u s e

    i f w e w e r e a b l e t o t h e n w e w o u l d b e i n a s u p e r w i n n i n g p o s i t i o n , n o t n o r m a l ) .

    3 . B u t n o b o d y w a n t s t o m o v e t o a s u p e r w i n n i n g p o s i t i o n , b e c a u s e h e w i l l l o s e i n n e x t

    m o v e a f t e r t h a t . S o f o r p l a y e r s i t i s t h e s a m e s i t u a t i o n a s i f t h e r e w e r e n o m o v e s t o

    s u p e r w i n n i n g p o s i t i o n s .

    4 . T h e r e f o r e i f a g a m e G

    i s i n a n o r m a l p o s i t i o n t h e n t h e r s t p l a y e r w h o w i l l n o t b e

    a b l e t o m o v e i n a n o r m a l p o s i t i o n s w i l l h a v e t o m o v e t o a s u p e r w i n n i n g p o s i t i o n a n d

    h e w i l l l o s e . S o w e c a n r e d u c e o u r p r o b l e m t o t h e o r d i n a r y s u m o f g a m e s w h e r e

    s u b g a m e s a r e s u p e r p i l e s w i t h o u t t h e m o s t b o t t o m p i l e s .

    I n t h e n e x t s u b s e c t i o n w e w i l l g e n e r a l i z e t h i s r e s u l t f o r a l l W T I A g a m e s .

    5 . 1 A l g o r i t h m

    W e w i l l i n t r o d u c e w

    - f u n c t i o n t h a t g i v e s w

    - n u m b e r t o e v e r y p o s i t i o n o f t h e g a m e G

    a n d

    t h e n u s e i t t o d i v i d e a l l t h e p o s i t i o n s t o w i n n i n g a n d l o s i n g o n e s .

    D e n i t i o n 5 . 2 . A l l p o s s i b l e w - n u m b e r s a r e a l l n o n - n e g a t i v e i n t e g e r s e x t e n d e d b y s p e c i a l v a l u e s SL 6 a n d SW7 .

    6

    s t a n d s f o r s u p e r l o s i n g

    7

    s t a n d s f o r s u p e r w i n n i n g

    2 0

  • 8/7/2019 Composite Mathematical Games

    21/37

    D e n i t i o n 5 . 3 . L e t G(X, f) i s a g a m e . W e w i l l a s s i g n w - n u m b e r t o e v e r y p o s i t i o n x X.

    1 .w(x) = SL

    i fx

    i s a t e r m i n a l p o s i t i o n

    2 . w(x) = SW i f e x i s t s a t e r m i n a l p o s i t i o n u X a n d u f(x)

    3 . w(x) = min(n 0 : n / M) w h e r e M = {w(u) : u f(x), SW = w(u) = SL}

    N o t e 5 . 1 . I n w o r d s , w e a s s i g n

    SLt o t h e s u p e r l o s i n g p o s i t i o n s ,

    SWt o t h e s u p e r w i n n i n g

    p o s i t i o n s a n d t h e n a s s i g n o t h e r w

    - n u m b e r s i n t h e s a m e w a y a s b y t h e S p r a g u e - G r u n d y

    f u n c t i o n c o n s i d e r i n g o n l y a n o r m a l p o s i t i o n s s u b s e t o f X

    .

    C o r o l l a r y 5 . 1 . G i v e n g a m e G(X, f). T h e p o s i t i o n x X i s l o s i n g i f a n d o n l y i f w(x) =SL o r w(x) = 0 .

    P r o o f . I f

    w(x) = SLo r

    SWi t i s c l e a r . I f

    w(x) > 0i t i s p o s s i b l e f o r a p l a y e r t o m o v e

    t o

    w(y) = 0( L - p o s i t i o n s ) . I f

    w(x) = 0p l a y e r c a n m o v e o n l y t o t h e p o s i t i o n s

    yw h e r e

    w(y) = SWo r

    w(y) > 0( W - p o s i t i o n s ) .

    T h e o r e m 5 . 2 . G i v e n W T I A g a m e G(X, f)

    t h a t i s a c o m p o u n d o f s u b g a m e s G1(X1, f1),

    G2(X2, f2) , . . . Gn(Xn, fn). T h e p o s i t i o n x = [x1, x2, . . . xn] i s l o s i n g i f a n d o n l y i f a t l e a s t o n e o f t h e s e c o n d i t i o n s i s h e l d :

    1 . (i) w(xi) = SL

    2 . (i) w(xi) / {SL,SW} a n d w(x1) w(x2) . . . w(xn) = 0

    w h e r e x X a n d xi Xi .

    P r o o f . W e w i l l c h e c k i f o u r d i v i s i o n o f p o s i t i o n s i s c o r r e c t . A l l t h e t e r m i n a l p o s i t i o n s xh a v e o n e s u b g a m e xi t h a t i s s u p e r l o s i n g ( w(xi) = SL ) , b e c a u s e i f n o t t h e n a p l a y e r w o u l d b e a b l e t o m o v e .

    I f a p l a y e r i s i n a l o s i n g p o s i t i o n t h e n w(x) = SL

    o rw(x1) w(x2) . . . w(xn) = 0 .

    T h e r s t c a s e w e d i d a s a p a r t o f t h e t e r m i n a l p o s i t i o n s . I f a p l a y e r m o v e s i n a n y s u b g a m e

    kt h e n e i t h e r h e m o v e s t o t h e s u p e r w i n n i n g p o s i t i o n i n t h a t s u b g a m e o r t o t h e p o s i t i o n

    yw i t h

    w(y) = w(xk). I n b o t h c a s e s h e c a n m o v e o n l y t o w i n n i n g p o s i t i o n s . I f a p l a y e r i s i n a w i n n i n g p o s i t i o n t h e n

    w(x) = SWo r

    w(x1) w(x2) . . . w(xn) = 0 .I n t h e r s t c a s e w h i l e w(x) = SW t h e r e e x i s t s s u b g a m e xk s u c h t h a t w(xk) = SW. Ap l a y e r c a n m o v e i n t h i s s u b g a m e t o s u p e r l o s i n g p o s i t i o n . I f x o r a m o n g a l l

    w(xi) = 0 t h e n a p l a y e r c a n e a s i l y m o v e t o c h a n g e i t t o

    0. H e c a n d o i t i n t h e s a m e w a y a s i n t h e G a m e

    o f N i m .

    D e n i t i o n 5 . 4 . W e w i l l d e n e o p e r a t i o n w o n g a m e s G1, G2 a s a c o m b i n a t i o n o f g a m e s G1 a n d G2 i n a W T I A w a y .

    R e m a r k 5 . 1 . O p e r a t i o n

    w o n g a m e s i s a s s o c i a t i v e , c o m m u t a t i v e a n d w(G1 w G2) i se q u a l t o

    1 .SL

    i fw(G1) = SL o r w(G2) = SL

    2 .SW

    i fw(G1), w(G2) = SL a n d i f w(G1) = SW o r w(G2) = SW

    3 .w(G1) w(G2) o t h e r w i s e

    2 1

  • 8/7/2019 Composite Mathematical Games

    22/37

    5 . 2 R e l a t i o n s h i p b e t w e e n w - n u m b e r s a n d G r u n d y n u m b e r s

    W h e n u s i n g f u n c t i o n s t h a t a s s i g n v a l u e s t o t h e p o s i t i o n s , l i k e t h e S p r a g u e - G r u n d y , r e m o t e -

    n e s s , s u s p e n s e f u n c t i o n o r w

    - f u n c t i o n w e a r e s t i l l w o r k i n g w i t h t h e s a m e g a m e G

    . T h e s e

    f u n c t i o n s j u s t a l l o w u s t o l o o k a t t h e g a m e f r o m d i e r e n t v i e w s a n d u s e t h e o n e w e n e e d

    t o c o m b i n e i t w i t h t h e o t h e r g a m e s .

    T h e r e f o r e i f p o s i t i o n i n g a m e G

    i s l o s i n g t h e n i t i s l o s i n g i n a l l t h e v i e w s f r o m

    w h i c h w e a r e l o o k i n g a t i t .

    C o r o l l a r y 5 . 3 . I n g a m e G(X, f) w(x) = 0 o r w(x) = SL i f a n d o n l y i f g(x) = 0. 8

    N o t e 5 . 2 . W e k n o w t h a t

    w(x) = 0 g(x) = 0 . N o t i c e t h a t i t d o e s n o t w o r k t h e o t h e r w a y a n d

    g(x) = 0 w(x) = 0i s n o t t r u e .

    T h i s p r o p e r t y f r o m C o r o l l a r y 5 . 3 i s s o m e t i m e s v e r y u s e f u l . C o n s i d e r g a m e G = (A wB w C) D a n d t h a t n u m b e r o f p o s i t i o n s i n a l l t h e g a m e s i s a b o u t k . W e w a n t t o n d o u t i f G i s a l o s i n g p o s i t i o n . T r i v i a l a l g o r i t h m c a n s o l v e o u r p r o b l e m i n t i m e

    O(k4)b y s e a r c h i n g t h r o u g h a l l t h e p o s s i b l e p o s i t i o n s . W e c a n d o b e t t e r ,

    O(k3), b y n o t i c i n g

    t h a t g(G) = g(A w B w C) g(D). B u t i f w e a r e h a p p y w e c a n t r y t o c o m p u t e

    w(A w B w C) = w(A) w w(b) w w(C) a n d i f i t i s e q u a l t o 0 t h e n w e c a n d e d u c e f r o m t h a t

    g(A w B w C) = 0 a n d t h e n w h o l e o u r a l g o r i t h m w i l l t a k e o n l y O(k) s t e p s .

    5 . 3 A p p l i c a t i o n i n g a m e s

    I n t h i s s u b s e c t i o n w e w i l l d e m o n s t r a t e u s i n g o f

    w- n u m b e r s o n s i m p l e e x a m p l e s . T h e i r

    a p p l i c a t i o n o n d e g e n e r a t e d D o t s a n d B o x e s g a m e i s i n t h e n e x t s e c t i o n .

    W e w i l l s t a r t w i t h c a l c u l a t i o n o f w

    - n u m b e r s f o r L i m i t e d N i m w i t h s u b s t r a c t i o n s e t

    S = {1, 3, 4}:

    n 0 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8

    w ( n ) S L S W 0 S W S W 1 2 0 2 0 1 3 1 2 0 2 0 1 3

    g ( n ) 0 1 0 1 2 3 2 0 1 0 1 2 3 2 0 1 0 1 2

    E x a m p l e 5 . 2 . L e t s h a v e t h r e e L i m i t e d N i m g a m e s w i t h t h i s s u b s t r a c t i o n s e t a n d w i t h

    s i z e s 5

    ,8

    ,6

    w i t h t h e r u l e t h a t t h e o v e r a l l w i n n e r w i l l b e o n e w h o w i n s r s t o f t h e s e

    g a m e s . A p l a y e r w h o s e t u r n i t i s i n a w i n n i n g p o s i t i o n , b e c a u s e

    w(5) w w(8) w w(6) =1 w 2 w 2 = 1.

    9

    I f t h e s i z e s o f p i l e s w e r e 4

    ,6

    ,11

    t h e n a p l a y e r w i l l b e i n a w i n n i n g

    p o s i t i o n , t o o , b e c a u s e w(4) w w(6) w w(11) = SW w 2 w 3 = SW.

    N o t e 5 . 3 . I n a b o v e t a b l e f o r L i m i t e d N i m w e c a n s e e t h a t C o r o l l a r y 5 . 3 r e a l l y w o r k s . W e

    c a n a l s o s e e t h a t b o t h w

    - n u m b e r s a n d g r u n d y n u m b e r s b e c o m e p e r i o d i c . I t i s b e c a u s e

    v a l u e f o r p o s i t i o n x

    d e p e n d s o n l y o n l a s t k

    v a l u e s w h e r e k

    i s t h e m a x i m u m n u m b e r i n

    s u b s t r a c t i o n s e t .

    8

    W e c a n c r e a t e s i m i l a r e q u i v a l e n c e s f o r t h e o t h e r f u n c t i o n s a s w e l l

    9

    b yn

    i nw(n)

    w e m e a n t h e L i m i t e d N i m p o s i t i o n o f s i z e n

    2 2

  • 8/7/2019 Composite Mathematical Games

    23/37

    N o w c o n s i d e r A l l t h e K i n g ` s h o r s e s g a m e w i t h s l i g h t l y c h a n g e d r u l e s . A p l a y e r w h o s e

    t u r n i t i s m u s t c h o o s e o n e h o r s e a n d m o v e w i t h h i m . T h e p l a y e r w h o r s t m o v e s a n y h o r s e

    h o m e ( t o l e f t - u p

    2 2c o r n e r f r o m w h i c h h o r s e s a r e u n a b l e t o m o v e ) i s d e c l a r e d t h e w i n n e r .

    T h i s g a m e i s a W T I A c o m b i n a t i o n o f t h e g a m e s w i t h o n l y o n e h o r s e o n e a c h c h e s s b o a r d .

    F i g u r e 9 s h o w s u s w

    - n u m b e r s t h a t w i l l h e l p u s t o d e t e r m i n e t h e w i n n e r . T o n d o u t w h o

    i s t h e w i n n e r o f a g a m e i t i s e n o u g h t o u s e t h e o p e r a t i o n w a m o n g t h e p o s i t i o n s o f a l l t h e h o r s e s t h a t a r e p l a c e d o n c h e s s b o a r d .

    S L S L S W S W 0 0 1 1

    S L S L S W S W 0 0 2 1

    S W S W S W S W 1 2 3 2

    S W S W S W 1 2 1 2 1

    0 0 1 2 0 0 1 2

    0 0 2 1 0 0 2 1

    1 2 3 2 1 2 1 2

    1 1 2 1 2 1 2 0

    F i g u r e 9 : w

    - n u m b e r s f o r 8 8

    A l l t h e K i n g ` s h o r s e s m o d i c a t i o n

    N o t e 5 . 4 . L i k e w e a r e c o m b i n i n g d i e r e n t g a m e s u s i n g G r u n d y n u m b e r s w e c a n c o m b i n e

    d i e r e n t g a m e s a l s o u s i n g w

    - n u m b e r s . F o r e x a m p l e A l l t h e K i n g ` s h o r s e s m o d i c a t i o n w i t h

    L i m i t e d N i m g a m e s f r o m E x a m p l e 5 . 2 . W e j u s t p u t t o g e t h e r t h e i r w

    - n u m b e r s i n a u s u a l

    w a y .

    2 3

  • 8/7/2019 Composite Mathematical Games

    24/37

    6 T h e D o t s a n d B o x e s g a m e r e l o a d e d

    I n t h i s s e c t i o n w e w i l l g o b a c k t o t h e d e g e n e r a t e d D o t s a n d B o x e s g a m e . W e w i l l u s e t h e

    f a c t t h a t n o w w e h a v e a n e w t o o l i n t r o d u c e d i n t h e p r e v i o u s s e c t i o n : w

    - n u m b e r s .

    W e c o u l d e x a m i n e s m a l l e r g a m e s b y u s i n g t h e s t a n d a r d w i n n i n g - l o s i n g a l g o r i t h m b y

    s e a r c h i n g t h r o u g h t h e a l l p o s i t i o n s o f t h e g a m e . T h e p r o b l e m i s t h a t t h i s w o u l d t a k e

    h u g e a m o u n t o f t i m e f o r b i g g e r g a m e s . I f w e h a v e m n

    D o t s a n d b o x e s g a m e , i t h a s

    m(n 1)+(m 1)n l i n e s , s o i t h a s a l m o s t 2m(n1)+(m1)n p o s i t i o n s . I f w e w a n t t o e x a m i n e a l l o f t h e m t h e c o m p l e x i t y o f t h e s t a n d a r d a l g o r i t h m w i l l b e

    O(2m(n1)+(m1)n)t h a t i s

    a l m o s t t h e s a m e a s O(22mn)

    . B e c a u s e o f t h a t n o w a d a y s i t t a k e s a b o u t a m i n u t e t o e x a m i n e

    4 4p o s i t i o n o f t h e g a m e , a b o u t a h a l f o f t h e d a y t o e x a m i n e

    4 5p o s i t i o n a n d a b o u t a

    y e a r t o e x a m i n e 5 5 p o s i t i o n .

    F o r t u n a t e l y w e c a n p r o t f r o m t h e f a c t t h a t w e k n o w b e t t e r t h e s t r u c t u r e o f s o m e

    p o s i t i o n s a n d t h a t t h e y a r e j u s t a W T I A c o m b i n a t i o n o f s u b g a m e s . W e w i l l d e s c r i b e a n

    a l g o r i t h m i n t h e s e c o n d p a r t o f t h i s s e c t i o n .

    6 . 1 V a l u e s f o r s m a l l e r g a m e s

    I n F i g u r e 1 0 w e c a n s e e s o m e r a n d o m l y c h o s e n p o s i t i o n s o f t h e d e g e n e r a t e d D o t s a n d B o x e s

    g a m e . W e h a v e a n a l y z e d t h e s e p o s i t i o n s a n d h a v e f o u n d w

    - n u m b e r s b y u s i n g a n a l g o r i t h m

    d e s c r i b e d i n t h e p r e v i o u s s e c t i o n .

    w(d)=SW w(e)=1 w(f)=0

    w(a)=1 w(b)=0 w(c)=2

    F i g u r e 1 0 : P o s i t i o n s i n d e g e n e r a t e d D o t s a n d B o x e s g a m e

    N o w w e c a n c o m p a r e t h e s e r e s u l t s w i t h " l o o k a n d s e e " a p p r o a c h :

    1 . I t i s o b v i o u s t h a t t h e p o s i t i o n d

    ( i n F i g u r e 1 0 ) i s s u p e r w i n n i n g , b e c a u s e a p l a y e r w i l l

    w i n b y a d d i n g a n y n e w l i n e .

    2 4

  • 8/7/2019 Composite Mathematical Games

    25/37

  • 8/7/2019 Composite Mathematical Games

    26/37

    A l t h o u g h B F S f o r e v e r y p o s i t i o n w i l l s l o w u s d o w n a b o u t mn

    t i m e s , w e a r e i n t e r e s t e d i n

    g a m e s w h e r e mn

    i s o n l y a b o u t 30

    , s o w e c a n l o o k a t i t a s a t s m a l l c o n s t a n t .

    O n t h e o t h e r h a n d w e w i l l g a i n m u c h m o r e . I n F i g u r e 1 1 w e n e e d e d o n l y a b o u t

    212

    o p e r a t i o n s t o c a l c u l a t e a n d c o m b i n e v a l u e s f o r t h e p o s i t i o n s a

    a n de

    . I f w e u s e d t h e

    s t a n d a r d a l g o r i t h m t o n d a v a l u e f o r t h e p o s i t i o n p

    w e w o u l d n e e d a b o u t 227

    o p e r a t i o n s .

    W e a r e c a l c u l a t i n g w

    - n u m b e r s r e c u r s i v e l y f o r t h e s u b g a m e s s o w e w i l l g e t t h e r e s u l t s e v e n

    f a s t e r a s a n a d d i t i o n a l b o n u s .

    w(s)=2 w(t)=1 w(u)=0

    + +

    w(v)=3

    =

    F i g u r e 1 2 : S u m o f t h e p o s i t i o n s i n d e g e n e r a t e d D o t s a n d B o x e s g a m e

    E x a m p l e 6 . 2 . F i g u r e 1 2 s h o w s u s h o w t o d i v i d e t h e p o s i t i o n

    vi n t o t h e s u b g a m e s

    s,

    ta n d

    u. W h i l e

    vi s a W T I A c o m b i n a t i o n o f t h e m w e o b t a i n t h a t

    w(v) = w(s) w w(t) w w(u) =2 w 1 w 0 = 3. S o n o w w e k n o w m u c h f a s t e r t h a t t h e p o s i t i o n v i s a w i n n i n g o n e . A n d m u c h m o r e w e k n o w t h a t w e c a n n d a w i n n i n g m o v e i n t h e s u b g a m e

    sa n d d e c r e a s e i t s

    w- n u m b e r t o

    1t o o b t a i n o v e r a l l s u m e q u a l t o

    0. A l l b o x e s i n t h e p o s i t i o n

    se x c e p t t w o a t

    t h e b o t t o m h a s t w o l i n e s . I f w e a d d t o o n e o f t h e s e t w o a b o t t o m l i n e o u r o p p o n e n t w i l l

    h a v e t o a d d t h e s e c o n d o n e ( o r m o v e t o a s u p e r w i n n i n g p o s i t i o n t h a t m e a n s a n i m m e d i a t e

    l o s e f o r h i m ) . S o i f w e t a k e o n e o f t h e s e t w o b o t t o m l i n e s w e w i l l c h a n g e i t s w

    - n u m b e r t o

    1.

    2 6

  • 8/7/2019 Composite Mathematical Games

    27/37

  • 8/7/2019 Composite Mathematical Games

    28/37

    i s L o s i n g ( ) - r e t u r n s i f t h e c u r r e n t p o s i t i o n i s l o s i n g

    g e t G r u n d y N u m b e r ( ) - r e t u r n s G r u n d y n u m b e r f o r t h e c u r r e n t p o s i t i o n

    g e t W T I A N u m b e r ( ) - r e t u r n s

    w- n u m b e r f o r t h e c u r r e n t p o s i t i o n

    g e t R e m o t e n e s s ( ) - r e t u r n s r e m o t e f u n c t i o n v a l u e f o r t h e c u r r e n t p o s i t i o n

    g e t S u s p e n s e ( ) - r e t u r n s s u s p e n s e f u n c t i o n v a l u e f o r t h e c u r r e n t p o s i t i o n .

    U s i n g S t r a t e g y p a t t e r n , a l l t h e s e a l g o r i t h m s a r e i m p l e m e n t e d i n t h e i r o w n c l a s s e s ( s e e

    F i g u r e 1 4 ) a n d a b s t r a c t c l a s s P o s i t i o n i s j u s t c a l l i n g t h e m b y d e f a u l t . O f c o u r s e t h e y c a n

    b e o v e r r i d d e n i f w e a r e c r e a t i n g o u r g a m e b y e x t e n d i n g t h e c l a s s P o s i t i o n a n d k n o w f r o m

    t h e s t r u c t u r e o f t h e g a m e h o w t o c o m p u t e a n y o f t h e s e v a l u e s f a s t e r . W e w i l l r e t u r n b a c k

    t o t h i s o p t i o n l a t e r o n .

    A l l a l g o r i t h m s s u p p o r t b u i l t - i n c a c h i n g

    t o i m p r o v e p e r f o r m a n c e a n d n o t t o c o m p u t e

    a n y t h i n g t w i c e . B u t i f w e w a n t t o u s e i t w e h a v e t o t e l l t h e c o m p u t e r w h e n t w o p o s i t i o n s

    a r e e q u a l . T o i m p l e m e n t t h i s w e h a v e t o o v e r r i d e m e t h o d s e q u a l s ( O b j e c t o )

    a n dh a s h -

    C o d e ( ) . W h i l e i m p l e m e n t i n g t h e m k e e p i n m i n d t h a t a c c o r d i n g t o J a v a c o n t r a c t i f t w o

    o b j e c t s t h a t a r e e q u a l t h e y m u s t h a v e t h e s a m e h a s h c o d e

    1 2

    .

    T h e l a s t m e t h o d o f t h e P o s i t i o n c l a s s i s d r a w ( P o s i t i o n V i s i t o r v )

    . T h i s m e t h o d i n -

    t r o d u c e s a d e s i g n p a t t e r n V i s i t o r t o o u r c l a s s P o s i t i o n . B y i n v o k i n g i t i t c a l l s t h e m e t h o d

    d r a w o n P o s i t i o n V i s i t o r a n d p r o v i d e s h i m w h o l e p o s i t i o n a s a p a r a m e t e r . T h e r e f o r e i f u s e r

    w a n t s t o g e t i n f o r m a t i o n a b o u t t h e c u r r e n t p o s i t i o n h e j u s t n e e d s t o i m p l e m e n t i n t e r f a c e

    P o s i t i o n V i s i t o r a n d c a l l m e t h o d d r a w w i t h i t a s a p a r a m e t e r . T h i s i m p l e m e n t a t i o n d e c o u -

    p l e s a n y o u t p u t a b o u t t h e c u r r e n t s t a t e f r o m t h e l o g i c o f t h e p o s i t i o n b e h a v i o u r . W e h a v e

    a l s o f r e e d o m t o h a v e m u l t i p l e v i s i t o r s f o r o n e g a m e : o n e t o g e n e r a t e t e x t o u t p u t t o t h e

    c o n s o l e o r g r a p h i c a l s w i n g , h t m l , . . . F o r e x a m p l e w e h a v e c r e a t e d m e t a p o s t P o s i t i o n V i s i t o r

    ( s e e F i g u r e 1 6 ) f o r t h e D o t s a n d B o x e s g a m e t o g e n e r a t e p i c t u r e s o f t h e p o s i t i o n s f o r t h i s

    t h e s i s .

    7 . 2 M o r e d e t a i l s o f t e c h n i c a l d e s i g n

    A n i d e a w a s t o c r e a t e a n e n v i r o n m e n t t h a t w i l l a l l o w u s t o c r e a t e g a m e s a s a c o m p o u n d o f

    t h e o t h e r g a m e s a n d p e r f o r m a l l o p e r a t i o n s o n t h e m l i k e i f t h e y w e r e s i m p l e g a m e s . O n t h e

    o t h e r h a n d w e w a n t t o p r o t f r o m t h e f a c t t h a t w e k n o w t h e s t r u c t u r e s o w e c a n c o m p u t e

    s o m e v a l u e s l i k e f o r e x a m p l e G r u n d y n u m b e r s m u c h f a s t e r . I n F i g u r e 1 5 i t c a n b e s e e n