DEATH

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

commit
0131974493cb44a61bfdf9f6c6eb4a43b1bba059
parent
3c09e40f2ead2ec4043082b013a9bb87de0c11f2
Author
Tobias Bengfort <tobias.bengfort@gmx.net>
Date
2014-05-25 19:57
change player id (-1)

Diffstat

M DEATH/DeathCli.py 8 ++++----
M DEATH/death.py 14 +++++++-------
M DEATH/matrix.py 7 +++++--
M DEATH/win.py 4 ++--

4 files changed, 18 insertions, 15 deletions


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

@@ -78,10 +78,10 @@ class DeathCli:
   78    78 		for i in range(self.death.map.rows):
   79    79 			for j in range(self.death.map.cols):
   80    80 				field = self.death.map.getitem(i, j)
   81    -1 				if field == 0:
   -1    81 				if field < 0:
   82    82 					s = ' '
   83    83 				else:
   84    -1 					s = str(field)
   -1    84 					s = str(field + 1)
   85    85 				if i == self.row and j == self.col:
   86    86 					self.screen.addstr(y0 + i, x0 + 2*j, s, curses.color_pair(1))
   87    87 				else:
@@ -102,10 +102,10 @@ class DeathCli:
  102   102 			if self.col > 0:
  103   103 				self.col -= 1
  104   104 		elif key == ord(' '):
  105    -1 			self.death.map.setitem(self.row, self.col, self.death.id + 1)
   -1   105 			self.death.map.setitem(self.row, self.col, self.death.id)
  106   106 			self.death.next()
  107   107 		elif key == curses.KEY_BACKSPACE:
  108    -1 			self.death.map.setitem(self.row, self.col, 0)
   -1   108 			self.death.map.clear(self.row, self.col)
  109   109 		elif key == ord('\n'):
  110   110 			self.death.step()
  111   111 		elif key == ord('\t'):

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

@@ -34,22 +34,22 @@ class Death:
   34    34 	def step_one(self, id):
   35    35 		# main logic of the game
   36    36 		def f(x):
   37    -1 			if x[0] == 0:
   -1    37 			if x[0] < 0:
   38    38 				if x[1] in self.born[id]:
   39    -1 					return id + 1
   -1    39 					return id
   40    40 				else:
   41    41 					return x[0]
   42    -1 			elif x[0] == id + 1:
   -1    42 			elif x[0] == id:
   43    43 				if x[1] in self.alive[id]:
   44    44 					return x[0]
   45    45 				else:
   46    -1 					return 0
   -1    46 					return -1
   47    47 			else:
   48    48 				if x[1] in self.kill[id]:
   49    -1 					return 0
   -1    49 					return -1
   50    50 				else:
   51    51 					return x[0]
   52    -1 		self.map.join([self.map, self.map.neighbors([id + 1])])
   -1    52 		self.map.join([self.map, self.map.neighbors([id])])
   53    53 		self.map.apply_f(f)
   54    54 
   55    55 	def step(self):
@@ -62,7 +62,7 @@ class Death:
   62    62 	def count(self):
   63    63 		c = []
   64    64 		for id in range(self.n):
   65    -1 			c.append(self.map.count(id + 1))
   -1    65 			c.append(self.map.count(id))
   66    66 		return c
   67    67 
   68    68 	def win(self):

diff --git a/DEATH/matrix.py b/DEATH/matrix.py

@@ -3,7 +3,7 @@
    3     3 
    4     4 
    5     5 class Matrix:
    6    -1 	def __init__(self, rows, cols, value=0):
   -1     6 	def __init__(self, rows, cols, value=-1):
    7     7 		self.rows = rows
    8     8 		self.cols = cols
    9     9 		self.value = value
@@ -59,10 +59,13 @@ class Matrix:
   59    59 
   60    60 
   61    61 class Map(Matrix):
   62    -1 	def __init__(self, rows=15, cols=15, diagonal=True, value=0):
   -1    62 	def __init__(self, rows=15, cols=15, diagonal=True, value=-1):
   63    63 		Matrix.__init__(self, rows, cols, value)
   64    64 		self.diagonal = diagonal
   65    65 
   -1    66 	def clear(self, i, j):
   -1    67 		self.setitem(i, j, -1)
   -1    68 
   66    69 	def neighbors(self, id, reverse=False):
   67    70 		try:
   68    71 			0 in id

diff --git a/DEATH/win.py b/DEATH/win.py

@@ -12,7 +12,7 @@ def death_match(_map, n):
   12    12 	# destroy every foe unit
   13    13 	winner = None
   14    14 	for id in range(n):
   15    -1 		if _map.count(id + 1) > 0:
   -1    15 		if _map.count(id) > 0:
   16    16 			if winner:
   17    17 				return None
   18    18 			else:
@@ -35,6 +35,6 @@ def capturetheflag(_map, n):
   35    35 def economy(_map, n):
   36    36 	k = int(_map.rows * _map.cols / n * 0.2)  # TODO?
   37    37 	for id in range(n):
   38    -1 		if _map.count(id + 1) >= k:
   -1    38 		if _map.count(id) >= k:
   39    39 			return id
   40    40 	return None