DEATH

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

commit
d22caa80f28957efd480148c4dd1d77318bb1b85
parent
0131974493cb44a61bfdf9f6c6eb4a43b1bba059
Author
Tobias Bengfort <tobias.bengfort@gmx.net>
Date
2014-05-25 20:00
rename id to player

Diffstat

M DEATH/DeathCli.py 6 +++---
M DEATH/death.py 26 +++++++++++++-------------
M DEATH/death_extra.py 2 +-
M DEATH/matrix.py 16 ++++++++--------
M DEATH/win.py 12 ++++++------

5 files changed, 31 insertions, 31 deletions


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

@@ -65,7 +65,7 @@ class DeathCli:
   65    65 		for y in range(h):
   66    66 			self.screen.addstr(y0 + y, x0 - 1, '|', curses.color_pair(2))
   67    67 			self.screen.addstr(y0 + y, x0 + w, '|', curses.color_pair(2))
   68    -1 		self.screen.addstr(y0 + h, x0 + w, str(self.death.id + 1),
   -1    68 		self.screen.addstr(y0 + h, x0 + w, str(self.death.player + 1),
   69    69 			curses.color_pair(2))
   70    70 		# count
   71    71 		self.screen.addstr(y0 - 1, x0 + 2,
@@ -102,14 +102,14 @@ 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   105 			self.death.map.setitem(self.row, self.col, self.death.player)
  106   106 			self.death.next()
  107   107 		elif key == curses.KEY_BACKSPACE:
  108   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'):
  112    -1 			self.death.step_one(self.death.id)
   -1   112 			self.death.step_one(self.death.player)
  113   113 			self.death.next()
  114   114 		elif key == ord('h'):
  115   115 			self.screen.clear()

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

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

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

@@ -14,7 +14,7 @@ def test(rows=15, cols=15, n=2):
   14    14 	alive = []
   15    15 	born = []
   16    16 	kill = []
   17    -1 	for id in range(n):
   -1    17 	for player in range(n):
   18    18 		alive.append(abk.conway[0])
   19    19 		born.append(abk.conway[1])
   20    20 		kill.append(abk.conway[2])

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

@@ -66,13 +66,13 @@ class Map(Matrix):
   66    66 	def clear(self, i, j):
   67    67 		self.setitem(i, j, -1)
   68    68 
   69    -1 	def neighbors(self, id, reverse=False):
   -1    69 	def neighbors(self, players, reverse=False):
   70    70 		try:
   71    -1 			0 in id
   -1    71 			0 in players
   72    72 		except:
   73    -1 			id = [id]
   -1    73 			players = [players]
   74    74 		if reverse:
   75    -1 			id.append(self.value)
   -1    75 			players.append(self.value)
   76    76 		result = Map(self.rows, self.cols, self.diagonal)
   77    77 		for i in range(self.rows):
   78    78 			for j in range(self.cols):
@@ -80,10 +80,10 @@ class Map(Matrix):
   80    80 				for cood in [(i + 1, j), (i, j + 1), (i - 1, j), (i, j - 1)]:
   81    81 					try:
   82    82 						if reverse:
   83    -1 							if self.getitem(cood[0], cood[1]) not in id:
   -1    83 							if self.getitem(cood[0], cood[1]) not in players:
   84    84 								a += 1
   85    85 						else:
   86    -1 							if self.getitem(cood[0], cood[1]) in id:
   -1    86 							if self.getitem(cood[0], cood[1]) in players:
   87    87 								a += 1
   88    88 					except:
   89    89 						pass
@@ -92,10 +92,10 @@ class Map(Matrix):
   92    92 							(i - 1, j - 1)]:
   93    93 						try:
   94    94 							if reverse:
   95    -1 								if self.getitem(cood[0], cood[1]) not in id:
   -1    95 								if self.getitem(cood[0], cood[1]) not in players:
   96    96 									a += 1
   97    97 							else:
   98    -1 								if self.getitem(cood[0], cood[1]) in id:
   -1    98 								if self.getitem(cood[0], cood[1]) in players:
   99    99 									a += 1
  100   100 						except:
  101   101 							pass

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

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