Karl Bartel avatar Karl Bartel committed a272ca2

applied numpy conversion patched by John Lightsey

Comments (0)

Files changed (12)

-from Numeric import *
+from numpy.oldnumeric import *
 from game import game
 
 class BaseAI:

src/battleplayer.py

 import pygame
 from pygame.locals import *
-from Numeric import *
+from numpy.oldnumeric import *
 
 import common
 import random

src/buildplayer.py

 import pygame
 from pygame.locals import *
-from Numeric import *
+from numpy.oldnumeric import *
 import common
 import random
 from copy import copy
 
 	def move(self, vector):
 		old_pos = self.pos
-		self.pos = add(self.pos, vector)
+		self.pos = tuple(add(self.pos, vector))
 		if self.pos != self.bounded_pos():
 			self.pos = old_pos
 			raise common.ActionNotPossible
 					if self.block[i][-side]:
 						margin[1][side] = 0
 
-		return [common.bound(self.pos[dim], 1-margin[dim][0], common.field_size[dim] - 2 + margin[dim][1]) for dim in (0,1)]
+		return tuple(common.bound(self.pos[dim], 1-margin[dim][0], common.field_size[dim] - 2 + margin[dim][1]) for dim in (0,1))
 	
 	def rotate_block(self):
 		if not self.block:
+## Automatically adapted for numpy.oldnumeric Sep 27, 2009 by 
+
 import pygame
 from pygame.locals import *
-from Numeric import *
+from numpy.oldnumeric import *
 import os
 
 debug = False
 
 def coords(stop):
 	i = indices(stop)
-	return zip(i[0].flat, i[1].flat)
+	return zip(i[0].ravel(), i[1].ravel())
 
 def bound(var, lower, upper):
 	return max( min(var, upper), lower)
+## Automatically adapted for numpy.oldnumeric Sep 27, 2009 by 
+
 import pygame
 from pygame.locals import *
-from Numeric import *
+from numpy.oldnumeric import *
 from random import randint
 from twisted.spread import pb
 from copy import deepcopy
 		self.time_to_action -= passed_milliseconds
 		if self.time_to_action <= 0:
 			# have a look at my movement possibilities 
-			new_pos = add(self.pos, self.movement[self.direction])
+			new_pos = tuple(add(self.pos, self.movement[self.direction]))
 			if common.is_in_bounds(new_pos):
 				wall_in_front = game.field[new_pos] >= 0
 			else:
 				wall_in_front = False
 			wall_in_sight = randint(0, 3)
 			for i in range(randint(0, 10)):
-				test_pos = add(self.pos, multiply(self.movement[self.direction], i))
+				test_pos = tuple(add(self.pos, multiply(self.movement[self.direction], i)))
 				if not common.is_in_bounds(test_pos) or game.field[test_pos] in (Field.CASTLE, Field.HOUSE, Field.RIVER) + Field.ANY_GARBAGE:
 					wall_in_sight = False
 					break
 			return is_river_large
 
 		def scatter(source):
-			import RandomArray
+			import numpy.oldnumeric.random_array as RandomArray
 			shift3d = RandomArray.randint(-2, 2, (2,) + source.shape)
 			shift = shift3d[1] * source.shape[1] + shift3d[0]
 			length = product(source.shape)
 			source_indices = zeros(source.shape)
-			source_indices.flat[:] = arange(length) + shift.flat
+			source_indices.flat[:] = arange(length) + shift.ravel()
 			source_indices = maximum(source_indices, 0)
 			source_indices = minimum(source_indices, length-1)
 
-			dest = take(source.flat, source_indices)
+			dest = take(source.ravel(), source_indices)
 			
 			return dest
 
 
 			# check which parts have changed
 			different = (old_secured != player.secured)
-			changed_fields = nonzero(different.flat).tolist()
+			changed_fields = nonzero(different.ravel()).tolist()
 			changed_fields.reverse()
 			for index in changed_fields:
 				x, y = divmod(index, field_size)
 			common.flood_fill2(fill_map, (1,1), False, True)
 		else:
 			# just calculate the changes caused by changeing the value at restart_at
-			restart_at = add(restart_at, 2)
+			restart_at = tuple(add(restart_at, 2))
 			fill_map = player.fill_map
 			unsecured_surroundings = fill_map[restart_at[0]-1:restart_at[0]+2, restart_at[1]-1:restart_at[1]+2] == 1
-			if not nonzero(ravel(unsecured_surroundings)):
-				restart_at = subtract(restart_at, 2)
+			if not any(nonzero(ravel(unsecured_surroundings))):
+				restart_at = tuple(subtract(restart_at, 2))
 				player.secured[restart_at] = True
 				#common.backbuffer.blit(player.ground_pic, [restart_at[i] * common.block_size for i in (0,1)])
 				#self.update(restart_at)
 import pygame
 from pygame.locals import *
-from Numeric import *
+from numpy.oldnumeric import *
 from twisted.spread import pb
 
 import common

src/gamephases.py

 import pygame
 from pygame.locals import *
-from Numeric import *
+from numpy.oldnumeric import *
 
 import common
 from game import game
 from random import randint
-from Numeric import *
+from numpy.oldnumeric import *
 from twisted.spread import pb
 
 import common
 	def add_grunts(self, amount):
 		player = game.players[0]
 		while amount > 0:
-			pos = [randint(0, max-1) for max in common.field_size]
+			pos = tuple(randint(0, max-1) for max in common.field_size)
 			if game.field[pos] == Field.EMPTY and not player.secured[pos]:
 				Grunt(pos)
 				amount -= 1
 					return True
 
 			while True:
-				pos = [randint(0,common.field_size[i]) for i in (0,1)]
+				pos = tuple(randint(0,common.field_size[i]) for i in (0,1))
 				if is_place_suitable(pos):
 					self.castles += [ Castle(pos=pos, player=None, map=self), ]
 					return

src/placeplayer.py

 import pygame
 from pygame.locals import *
-from Numeric import *
+from numpy.oldnumeric import *
 
 import common
 from game import game
 		common.blit(Cannon.cannon_pic[self.selected_type][0], (self.pos[0]*common.block_size, self.pos[1]*common.block_size) )
 
 		for offset in common.coords( (2 + self.selected_type, )*2):
-			pos = add(self.pos, offset)
+			pos = tuple(add(self.pos, offset))
 			if game.field.array[pos] != Field.EMPTY or self.player.secured[pos] == 0:
 				common.blit(self.cantbuild_pic, multiply(pos, common.block_size))
 
 import pygame
 from pygame.locals import *
-from Numeric import *
+from numpy.oldnumeric import *
 from twisted.spread import pb
 
 import common

src/selectplayer.py

 import pygame
 from pygame.locals import *
-from Numeric import *
+from numpy.oldnumeric import *
 
 import common
 from game import game
 import pygame
 from pygame.locals import *
-from Numeric import *
+from numpy.oldnumeric import *
 import common
 from state import State, IgnoreEvent
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.