Dr.Magic
I know you know!
posts - 9,comments - 3,trackbacks - 0
  1 #-*- coding:utf-8 -*-
  2 #           N:0
  3 #      NW:1     EN:7
  4 #   W:2             E:6
  5 #      WS:3     SE:5         
  6 #           S:4
  7 # x\y
  8 #   00 -01-02-03-04-05-06-07-08 R=True Red
  9 #    |  |  |  | \ |/ |  |  |  |
 10 #   10 -11-12-13-14-15-16-17-18
 11 #    |  |  |  | / |\ |  |  |  |
 12 #   20 -21-22-23-24-25-26-27-28
 13 #    |  |  |  |   |  |  |  |  |
 14 #   30 -31-32-33-34-35-36-37-38
 15 #    |  |  |  |   |  |  |  |  |
 16 #   40 -41-42-43-44-45-46-47-48
 17 #    |                        |
 18 #   50 -51-52-53-54-55-56-57-58
 19 #    |  |  |  |   |  |  |  |  |  
 20 #   60 -61-62-63-64-65-66-67-68
 21 #    |  |  |  |   |  |  |  |  |
 22 #   70 -71-71-73-74-75-76-77-78
 23 #    |  |  |  | \ |/ |  |  |  |
 24 #   80 -81-82-83-84-85-86-87-88
 25 #    |  |  |  | / |\ |  |  |  |
 26 #   90 -91-92-93-94-95-96-97-98 R=False Black
 27 diction={}
 28 class Chess:
 29     def __init__(self,x,y):
 30         self.pos=Pos(x,y)
 31         self.get_direct()
 32     def can_move_to(self,pos):
 33         return False;
 34     def get_direct(self):
 35         self.direct=[]
 36 
 37 class Bin(Chess):
 38     def __init__(self,x,y,R=True):
 39         self.r = R
 40         Chess.__init__(self,x,y)
 41     def get_direct(self):
 42         if self.r:# up side
 43             if self.pos.x < 5:
 44                 self.direct = [4]
 45             elif self.pos.x<9 and self.pos.x>=5:
 46                 if self.pos.y==0:   
 47                     self.direct = [4,6]
 48                 elif self.pos.y==8:
 49                     self.direct = [2,4]
 50                 else:
 51                     self.direct = [2,4,6]
 52             else:
 53                 if self.pos.y==0:   
 54                     self.direct = [6]
 55                 elif self.pos.y==8:
 56                     self.direct = [2]
 57         else# down side
 58             if self.pos.x > 4:
 59                 self.direct = [0]
 60             elif self.pos.x>and self.pos.x<=4#  0 < x < =4
 61                 if self.pos.y==0:   
 62                     self.direct = [0,6]
 63                 elif self.pos.y==8:
 64                     self.direct = [0,2]
 65                 else:
 66                     self.direct = [0,2,6]
 67             else:
 68                 if self.pos.y==0:   
 69                     self.direct = [6]
 70                 elif self.pos.y==8:
 71                     self.direct = [2]
 72     def can_move_to(self,pos):
 73         # move in H 横移
 74         if pos.x==self.pos.x:
 75             if pos.y==self.pos.y+1 and (6 in self.direct):
 76                 return True
 77             elif pos.y==self.pos.y-1 and (2 in self.direct):
 78                 return True
 79         # move in V 纵移
 80         if pos.y==self.pos.y:
 81             if pos.x==self.pos.x+1 and self.r and (4 in self.direct):
 82                 return True
 83             if pos.x==self.pos.x-1 and not self.r and (0 in self.direct):
 84                 return True
 85         return False
 86 
 87 class Shi(Chess):
 88     def __init__(self,x,y,R=True):
 89         Chess.__init__(self,x,y)
 90         self.r = R
 91     def get_direct(self):
 92         if self.pos.x==0:
 93             if self.pos.y==3:
 94                 self.direct=[5]
 95             else:
 96                 self.direct=[3]
 97         elif self.pos.x==2:
 98             if self.pos.y==3:
 99                 self.direct=[7]
100             else:
101                 self.direct=[1]
102         else:
103             self.direct=[1,3,5,7]
104     
105     def can_move_to(self,pos):
106         if pos.x==self.pos.x-1 and pos.y==self.pos.y+1:
107             if 7 in self.direct:
108                 return True
109         if pos.x==self.pos.x+1 and pos.y==self.pos.y+1:
110             if 5 in self.direct:
111                 return True
112         if pos.x==self.pos.x+1 and pos.y==self.pos.y-1:
113             if 3 in self.direct:
114                 return True
115         if pos.x==self.pos.x-1 and pos.y==self.pos.y-1:
116             if 1 in self.direct:
117                 return True
118         return False
119 
120 class Xiang(Chess):
121     def __init__(self,x,y,R=True):
122         Chess.__init__(self,x,y)
123         self.r = R
124     def get_direct(self):
125         if self.pos.x==0:
126             self.direct=[3,5]
127         elif self.pos.x==4:
128             self.direct=[1,7]
129         elif self.pos.y==0:
130             self.direct=[5,7]
131         else:
132             self.direct=[1,3]
133     def can_move_to(self,pos):
134         if pos.x==self.pos.x-2 and pos.y==self.pos.y+2:
135             if 7 in self.direct:
136                 return True
137         if pos.x==self.pos.x+2 and pos.y==self.pos.y+2:
138             if 5 in self.direct:
139                 return True
140         if pos.x==self.pos.x+2 and pos.y==self.pos.y-2:
141             if 3 in self.direct:
142                 return True
143         if pos.x==self.pos.x-2 and pos.y==self.pos.y-2:
144             if 1 in self.direct:
145                 return True
146         return False
147     
148 class Pao(Chess):
149     def __init__(self,x,y,R=True):
150         Chess.__init__(self,x,y)
151         self.r = R
152     def get_direct(self):
153         if self.pos.x==0:
154             if self.pos.y==0:
155                 self.direct=[4,6]
156             elif self.pos.y==8:
157                 self.direct=[2,4]
158             else:
159                 self.direct=[2,4,6]
160         elif self.pos.x==9:
161             if self.pos.y==0:
162                 self.direct=[0,6]
163             elif self.pos.y==8:
164                 self.direct=[0,2]
165             else:
166                 self.direct=[0,2,6]
167         else:
168             self.direct=[0,2,4,6]
169 
170 class Ma(Chess):
171     def __init__(self,x,y,R=True):
172         Chess.__init__(self,x,y)
173         self.r = R
174     def get_direct(self):
175         if self.pos.x==0:
176             if self.pos.y==0:
177                 self.direct=[5]
178             elif self.pos.y==8:
179                 self.direct=[3]
180             else:
181                 self.direct=[3,5]
182         elif self.pos.x==9:
183             if self.pos.y==0:
184                 self.direct=[7]
185             elif self.pos.y==8:
186                 self.direct=[1]
187             else:
188                 self.direct=[1,7]
189     def can_move_to(self,pos):
190         if pos.x==self.pos.x-2 and not diction.has_key( (self.pos.x-1,self.pos.y) ):
191             if pos.y==self.pos.y+1 and 7 in self.direct:
192                 return True
193             if pos.y==self.pos.y-1 and 1 in self.direct:
194                 return True
195         if pos.x==self.pos.x+2 and not diction.has_key( (self.pos.x+1,self.pos.y) ):
196             if pos.y==self.pos.y+1 and 5 in self.direct:
197                 return True
198             if pos.y==self.pos.y-1 and 3 in self.direct:
199                 return True
200         if pos.y==self.pos.y-2 and not diction.has_key( (self.pos.x,self.pos.y-1) ):
201             if pos.x==self.pos.x+1 and 3 in self.direct:
202                 return True
203             if pos.x==self.pos.x-1 and 1 in self.direct:
204                 return True
205         if pos.y==self.pos.y+2 and not diction.has_key( (self.pos.x,self.pos.y+1) ):
206             if pos.x==self.pos.x+1 and 5 in self.direct:
207                 return True
208             if pos.x==self.pos.x-1 and 7 in self.direct:
209                 return True
210         return False
211 class Ju(Chess):
212     def __init__(self,x,y,R=True):
213         Chess.__init__(self,x,y)
214         self.r = R
215     def get_direct(self):
216         if self.pos.x==0:
217             if self.pos.y==0:
218                 self.direct=[4,6]
219             elif self.pos.y==8:
220                 self.direct=[2,4]
221             else:
222                 self.direct=[2,4,6]
223         elif self.pos.x==9:
224             if self.pos.y==0:
225                 self.direct=[0,6]
226             elif self.pos.y==8:
227                 self.direct=[0,2]
228             else:
229                 self.direct=[0,2,6]
230         else:
231             self.direct=[0,2,4,6]
232     def can_move_to(self,pos):
233         # move in H 横移
234         if pos.x==self.pos.x:
235             if pos.y>self.pos.y and (6 in self.direct):
236                 return True
237             elif pos.y<self.pos.y and (2 in self.direct):
238                 return True
239         # move in V 纵移
240         if pos.y==self.pos.y:
241             if pos.x>self.pos.x and (4 in self.direct):
242                 return True
243         return False
244     
245 class King(Chess):
246     def __init__(self,x,y,R=True):
247         Chess.__init__(self,x,y)
248         self.r = R
249     def get_direct():
250         if self.pos.x==0:
251             if self.pos.y==3:
252                 self.direct=[4,6]
253             elif self.pos.y==5:
254                 self.direct=[2,4]
255             else:
256                 self.direct=[2,4,6]
257         elif self.pos.x==2:
258             if self.pos.y==3:
259                 self.direct=[0,6]
260             elif self.pos.y==5:
261                 self.direct=[0,2]
262             else:
263                 self.direct=[0,2,6]
264         elif self.pos.x==1:
265             if self.pos.y==3:
266                 self.direct=[0,4,6]
267             elif self.pos.y==5:
268                 self.direct=[0,2,4]
269             else:
270                 self.direct=[0,2,4,6]
271     
272 class Pos:
273     def __init__(self,x,y):
274         self.x = x
275         self.y = y
276     def trans():
277         self.x = 9-self.x
278         self.y = 8-self.y
279 if __name__=='__main__':
280     ma=Bin(5,3)
281     for i in ma.direct:
282         print i
283     print ma.can_move_to(Pos(5,1))
Just begin ...
posted on 2007-10-24 18:47 Dr.Magic 阅读(307) 评论(0)  编辑  收藏 所属分类: Just think a little

只有注册用户登录后才能发表评论。


网站导航:
博客园   IT新闻   Chat2DB   C++博客   博问