-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchessboard.py
68 lines (62 loc) · 1.54 KB
/
chessboard.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python
#-*-coding:utf-8-*-
import sys,time
from window import *
from music import *
class chess (object):
def __init__ (self, forbidden = 0):
self.__board = [ [ 0 for n in xrange(15) ] for m in xrange(15) ]
self.__dirs = ( (-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), \
(1, -1), (0, -1), (-1, -1) )
self.DIRS = self.__dirs
def reset (self):
for j in xrange(15):
for i in xrange(15):
self.__board[i][j] = 0
return 0
def get (self, row, col):
if row < 0 or row >= 15 or col < 0 or col >= 15:
return 0
return self.__board[row][col]
def put (self, row, col, x):
if row >= 0 and row < 15 and col >= 0 and col < 15:
self.__board[row][col] = x
return 0
def check (self):
board = self.__board
dirs = ((1, -1), (1, 0), (1, 1), (0, 1))
for i in xrange(15):
for j in xrange(15):
if board[i][j] == 0: continue
id = board[i][j]
for d in dirs:
x, y = j, i
count = 0
for k in xrange(5):
if self.get(y, x) != id: break
y += d[0]
x += d[1]
count += 1
if count == 5:
r, c = i, j
for z in xrange(5):
r += d[0]
c += d[1]
return id
return 0
def board (self):
return self.__board
def chboard(self,b):
self.__board=b
def win(self,result):
if result==1:
screen.blit(bwin,(550,193))
win_sound.play()
turn=3
result=0
if result==2:
screen.blit(wwin,(550,193))
win_sound.play()
turn=3
result=0
update()