DEATH

a multiplayer variant of conways game of LIFE
git clone https://git.ce9e.org/DEATH.git

commit
84a25fcce094da224c1a81f1420ee08730fe2b8a
parent
748a59da17fce65b6eb07163e1057992fcb05ae8
Author
Tobias Bengfort <tobias.bengfort@gmx.net>
Date
2011-03-11 08:49
win

Diffstat

M DeathCli.py 15 ++++++++++++---
D DeathCli.pyc 0
M DeathCliMenu.py 2 +-
M RULES 16 ++++++++++++++++
M death.py 6 ++++--
D death.pyc 0
M death_extra.py 47 ++++++++++++++++++-----------------------------
A death_extra_abk.py 9 +++++++++
C death_extra.py -> death_extra_win.py 51 ++++++++++++++++++++++++++++-----------------------
D matrix.pyc 0

10 files changed, 88 insertions, 58 deletions


diff --git a/DeathCli.py b/DeathCli.py

@@ -4,6 +4,7 @@
    4     4 import curses
    5     5 import optparse
    6     6 from death import Death
   -1     7 import death_extra
    7     8 
    8     9 help = """
    9    10 Welcome to DEATH !
@@ -32,9 +33,10 @@ return with any key
   32    33 class DeathCli:
   33    34   global help
   34    35 
   35    -1   def __init__(self, death=Death(), screen=curses.initscr()):
   -1    36   def __init__(self, death=death_extra.test(15,15,2), title='', screen=curses.initscr()):
   36    37     self.screen = screen
   37    38     self.death = death
   -1    39     self.title = title
   38    40     self.screen.clear()
   39    41     curses.curs_set(0)
   40    42     self.screen.keypad(1)
@@ -44,7 +46,12 @@ class DeathCli:
   44    46     self.row = 0
   45    47     self.col = 0
   46    48     self.draw()
   47    -1     while self.mainloop(): pass
   -1    49     while self.mainloop():
   -1    50       winner = self.death.win()
   -1    51       if winner:
   -1    52         print 'Player %s wins!' % (winner+1)
   -1    53         self.screen.getch()
   -1    54         break
   48    55 
   49    56   def draw(self):
   50    57     w = 2*self.death.map.cols-1
@@ -61,6 +68,8 @@ class DeathCli:
   61    68     self.screen.addstr(y0+h, x0+w, str(self.death.id+1), curses.color_pair(2))
   62    69     # count
   63    70     self.screen.addstr(y0-1, x0+2, '|'.join([str(a) for a in self.death.count()]), curses.color_pair(2))
   -1    71     # title
   -1    72     self.screen.addstr(y0-1, x0+w-len(self.title), self.title, curses.color_pair(2))
   64    73     # map
   65    74     for i in range(self.death.map.rows):
   66    75       for j in range(self.death.map.cols):
@@ -114,6 +123,6 @@ class DeathCli:
  114   123 if __name__ == '__main__':
  115   124   try: DeathCli()
  116   125   except Exception as ex:
  117    -1    print ex
   -1   126     print ex
  118   127   curses.endwin()
  119   128 

diff --git a/DeathCli.pyc b/DeathCli.pyc

Binary files differ.

diff --git a/DeathCliMenu.py b/DeathCliMenu.py

@@ -169,7 +169,7 @@ class Crs:
  169   169 
  170   170     _map = Map(rows, cols)
  171   171     d = Death(_map, n, alive, born, kill)
  172    -1     DeathCli(d, self.screen)
   -1   172     DeathCli(d, 'default', self.screen)
  173   173     return True
  174   174 
  175   175 if __name__ == '__main__':

diff --git a/RULES b/RULES

@@ -1,4 +1,20 @@
   -1     1 klassisch
   -1     2 23|3
   -1     3 
    1     4 statische grenzen -> wer bekommt mehr gebiet?
    2     5 zb
    3     6 012345678|34|345678
    4     7 01234567|34|345678
   -1     8 
   -1     9 capture the flag -> wer bekommt zuerst alle 4 ecken
   -1    10 Ecken müssen tötbar sein also entweder 3 not in alive oder kill <= 3
   -1    11 Ecken müssen besiedelbar sein, also born <= 3
   -1    12 
   -1    13 economy -> wer bekommt zuerst n felder
   -1    14 
   -1    15 
   -1    16 death math -> auslöschen der Gegner
   -1    17 Ecken müssen tötbar sein also entweder 3 not in alive oder kill <= 3
   -1    18 Ecken müssen besiedelbar sein, also born <= 3
   -1    19 
   -1    20 

diff --git a/death.py b/death.py

@@ -19,7 +19,7 @@ this happens in turns
   19    19 from matrix import Map
   20    20 
   21    21 class Death:
   22    -1   def __init__(self, _map=Map(), n=1, alive=[[2,3]], born=[[3]], kill=[[]], win=(lambda _map,n: None)):
   -1    22   def __init__(self, _map=Map(), n=1, alive=[[2,3]], born=[[3]], kill=[[]], win=lambda _map,n: None):
   23    23   # the defaults make death the standart life 
   24    24     self.n = n
   25    25     self.alive = alive
@@ -27,7 +27,7 @@ class Death:
   27    27     self.kill = kill
   28    28     self.map = _map
   29    29     self.id = 0
   30    -1     self.win = win
   -1    30     self._win = win
   31    31 
   32    32   def step_one(self,id):
   33    33     def f(x): 
@@ -64,3 +64,5 @@ class Death:
   64    64       c.append(self.map.count(id+1))
   65    65     return c
   66    66 
   -1    67   def win(self):
   -1    68     return self._win(self.map, self.n)

diff --git a/death.pyc b/death.pyc

Binary files differ.

diff --git a/death_extra.py b/death_extra.py

@@ -1,33 +1,22 @@
    1     1 #!/usr/bin/env python
    2     2 # -*- coding: utf-8 -*-
    3    -1  """
    4    -1 This contaions win-functions and alive/born/kill values
    5     3 
    6    -1 win-functions
    7    -1 * take a Map and number of players and 
    8    -1 * return the id of the winnig player or None
    9    -1 """
   10    -1 
   11    -1 class win:
   12    -1   def extinction(_map, n):
   13    -1     # destroy every foe unit
   14    -1     winner = None
   15    -1     for id in range(n):
   16    -1       if _map.count(id+1) > 0::
   17    -1         if winner:
   18    -1           return None
   19    -1         else
   20    -1            winner = id
   21    -1     return winner
   22    -1 
   23    -1   def capturetheflag(_map, n):
   24    -1     #  capture the four corners
   25    -1     flag1 = _map.getitem(0,0)
   26    -1     flag2 = _map.getitem(0,_map.cols-1)
   27    -1     flag3 = _map.getitem(_map.rows-1,_map.cols-1)
   28    -1     flag4 = _map.getitem(_map.rows-1,0)
   29    -1     if flag1 == flag2 and flag2 == flag3 and flag3 == flag4:
   30    -1       return flag1-1
   31    -1     else:
   32    -1       return None
   -1     4 from matrix import Map
   -1     5 from death import Death
   -1     6 import death_extra_win as win
   -1     7 import death_extra_abk as abk
   33     8 
   -1     9 """
   -1    10 complete games
   -1    11 """
   -1    12 def test(rows=15, cols=15, n=2):
   -1    13   map = Map(rows, cols)
   -1    14   alive = []
   -1    15   born = []
   -1    16   kill = []
   -1    17   for id in range(n):
   -1    18     alive.append(abk.conway[0])
   -1    19     born.append(abk.conway[1])
   -1    20     kill.append(abk.conway[2])
   -1    21   death = Death(map, n, alive, born, kill, win.economy)
   -1    22   return death

diff --git a/death_extra_abk.py b/death_extra_abk.py

@@ -0,0 +1,9 @@
   -1     1 #!/usr/bin/env python
   -1     2 # -*- coding: utf-8 -*-
   -1     3 
   -1     4 """
   -1     5 alive|born|kill
   -1     6 """
   -1     7 static_borders1 =  [[0,1,2,3,4,5,6,7,8],[3,4],[4,5,6,7,8]]
   -1     8 conway =  [[2,3],[3],[]]
   -1     9 

diff --git a/death_extra.py b/death_extra_win.py

@@ -1,33 +1,38 @@
    1     1 #!/usr/bin/env python
    2     2 # -*- coding: utf-8 -*-
    3    -1  """
    4    -1 This contaions win-functions and alive/born/kill values
    5     3 
   -1     4 """
    6     5 win-functions
    7     6 * take a Map and number of players and 
    8     7 * return the id of the winnig player or None
    9     8 """
   10     9 
   11    -1 class win:
   12    -1   def extinction(_map, n):
   13    -1     # destroy every foe unit
   14    -1     winner = None
   15    -1     for id in range(n):
   16    -1       if _map.count(id+1) > 0::
   17    -1         if winner:
   18    -1           return None
   19    -1         else
   20    -1            winner = id
   21    -1     return winner
   -1    10 def death_match(_map, n):
   -1    11   # destroy every foe unit
   -1    12   winner = None
   -1    13   for id in range(n):
   -1    14     if _map.count(id+1) > 0:
   -1    15       if winner:
   -1    16         return None
   -1    17       else:
   -1    18          winner = id
   -1    19   return winner
   -1    20 
   -1    21 def capturetheflag(_map, n):
   -1    22   #  capture the four corners
   -1    23   flag1 = _map.getitem(0,0)
   -1    24   flag2 = _map.getitem(0,_map.cols-1)
   -1    25   flag3 = _map.getitem(_map.rows-1,_map.cols-1)
   -1    26   flag4 = _map.getitem(_map.rows-1,0)
   -1    27   if flag1 == flag2 and flag2 == flag3 and flag3 == flag4:
   -1    28     return flag1-1
   -1    29   else:
   -1    30     return None
   22    31 
   23    -1   def capturetheflag(_map, n):
   24    -1     #  capture the four corners
   25    -1     flag1 = _map.getitem(0,0)
   26    -1     flag2 = _map.getitem(0,_map.cols-1)
   27    -1     flag3 = _map.getitem(_map.rows-1,_map.cols-1)
   28    -1     flag4 = _map.getitem(_map.rows-1,0)
   29    -1     if flag1 == flag2 and flag2 == flag3 and flag3 == flag4:
   30    -1       return flag1-1
   31    -1     else:
   32    -1       return None
   -1    32 def economy(_map, n):
   -1    33   k = int(_map.rows * _map.cols / n * 0.2) # TODO ?
   -1    34   for id in range(n):
   -1    35     if _map.count(id+1) >= k:
   -1    36       return id
   -1    37   return None
   33    38 

diff --git a/matrix.pyc b/matrix.pyc

Binary files differ.