Skip to content

Commit

Permalink
Support recent numpy versions
Browse files Browse the repository at this point in the history
  • Loading branch information
karlb committed Sep 28, 2019
1 parent a934233 commit 9b35d4e
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 25 deletions.
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pygame
numpy
twisted
2 changes: 1 addition & 1 deletion src/ai.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from numpy.oldnumeric import *
from numpy import *
from game import game

class BaseAI:
Expand Down
2 changes: 1 addition & 1 deletion src/battleplayer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pygame
from pygame.locals import *
from numpy.oldnumeric import *
from numpy import *

import common
import random
Expand Down
2 changes: 1 addition & 1 deletion src/buildplayer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pygame
from pygame.locals import *
from numpy.oldnumeric import *
from numpy import *
import common
import random
from copy import copy
Expand Down
9 changes: 4 additions & 5 deletions src/common.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
## Automatically adapted for numpy.oldnumeric Sep 27, 2009 by

import pygame
from pygame.locals import *
from numpy.oldnumeric import *
import numpy as np
from numpy import *
import os

debug = False
Expand Down Expand Up @@ -82,7 +81,7 @@ def colorize(surface, color):
#pixel_array = pixel_array * color
#pixel_array /= 255
#pygame.surfarray.blit_array(surface, pixel_array)
col = array(color, UInt8)
col = array(color, np.uint8)
for line in pixel_array:
for pixel in line:
for i in (0,1,2):
Expand All @@ -99,7 +98,7 @@ def multiply_alpha(surface, factor):
surface = surface.convert()

alpha = pygame.surfarray.pixels_alpha(surface)
divide(alpha, array(factor).astype(UInt8), alpha)
divide(alpha, array(factor).astype(np.uint8), alpha)
#multiply(alpha, array(factor), alpha)
return surface

Expand Down
18 changes: 9 additions & 9 deletions src/field.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
## Automatically adapted for numpy.oldnumeric Sep 27, 2009 by

import pygame
from pygame.locals import *
from numpy.oldnumeric import *
import numpy as np
from numpy import *
from random import randint
from twisted.spread import pb
from copy import deepcopy
Expand Down Expand Up @@ -147,6 +146,9 @@ def create_basic_background():
return is_river_large

def scatter(source):
return source
# implementation unmaintained
"""
import numpy.oldnumeric.random_array as RandomArray
shift3d = RandomArray.randint(-2, 2, (2,) + source.shape)
shift = shift3d[1] * source.shape[1] + shift3d[0]
Expand All @@ -159,6 +161,7 @@ def scatter(source):
dest = take(source.ravel(), source_indices)
return dest
"""

def colorize(source):
dest = zeros(source.shape + (3,))
Expand Down Expand Up @@ -273,11 +276,8 @@ def update_screen(old_secured, foreign_walls):
field_size = common.field_size[1]

# check which parts have changed
different = (old_secured != player.secured)
changed_fields = nonzero(different.ravel()).tolist()
changed_fields.reverse()
for index in changed_fields:
x, y = divmod(index, field_size)
changed_fields = np.argwhere(old_secured != player.secured)
for x, y in changed_fields:
# the screen has changed at x, y => update the screen
if not old_secured[x,y]:
screen_pos = (x*block_size, y*block_size)
Expand Down Expand Up @@ -322,7 +322,7 @@ def update_screen(old_secured, foreign_walls):

# eleminate other player's walls
foreign_walls = player.secured * (self.array >= 0) * (self.array != player.player_id)
putmask(self.array, foreign_walls, zeros(self.array.shape) + Field.EMPTY)
putmask(self.array, foreign_walls, zeros(self.array.shape, dtype=np.int64) + Field.EMPTY)

# now we know which areas are secured, so let's update the screen
update_screen(old_secured, foreign_walls)
Expand Down
2 changes: 1 addition & 1 deletion src/game.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pygame
from pygame.locals import *
from numpy.oldnumeric import *
from numpy import *
from twisted.spread import pb

import common
Expand Down
2 changes: 1 addition & 1 deletion src/gamephases.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pygame
from pygame.locals import *
from numpy.oldnumeric import *
from numpy import *

import common
from game import game
Expand Down
2 changes: 1 addition & 1 deletion src/map.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from random import randint
from numpy.oldnumeric import *
from numpy import *
from twisted.spread import pb
from twisted.internet import reactor

Expand Down
2 changes: 1 addition & 1 deletion src/placeplayer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pygame
from pygame.locals import *
from numpy.oldnumeric import *
from numpy import *

import common
from game import game
Expand Down
2 changes: 1 addition & 1 deletion src/player.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pygame
from pygame.locals import *
from numpy.oldnumeric import *
from numpy import *
from twisted.spread import pb

import common
Expand Down
2 changes: 1 addition & 1 deletion src/selectplayer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pygame
from pygame.locals import *
from numpy.oldnumeric import *
from numpy import *

import common
from game import game
Expand Down
5 changes: 3 additions & 2 deletions src/widget.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pygame
from pygame.locals import *
from numpy.oldnumeric import *
import numpy as np
from numpy import *
import common
from state import State, IgnoreEvent

Expand Down Expand Up @@ -63,7 +64,7 @@ def draw(self):
# Create 50% transparent surface
self.inactive_surface = self.normal_surface.convert_alpha()
alpha = pygame.surfarray.pixels_alpha(self.inactive_surface)
divide(alpha, array(2).astype(UInt8), alpha)
divide(alpha, array(2).astype(np.uint8), alpha)
del alpha
common.blit(self.inactive_surface, self.pos)
self.highlighted = False
Expand Down

0 comments on commit 9b35d4e

Please sign in to comment.