~parcheesi-team/parcheese/master

« back to all changes in this revision

Viewing changes to src/core/player.py

  • Committer: neonigma
  • Date: 2011-06-25 15:20:11 UTC
  • Revision ID: neonigma@gmail.com-20110625152011-5ypiqt77x4ti0lpb
Done rule [R07], difference between barriers, check when UI is ready

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#
3
3
# Copyright 2011 Parcheese Team.
4
4
# Author: J. Ignacio Alvarez <neonigma@gmail.com>
 
5
# Author: Luis Diaz Mas <piponazo@gmail.com>
5
6
# Author: Edorta Garcia Gonzalez <edortagarcia@gmail.com>
6
7
#
7
8
# Parcheese is free software; you can redistribute it and/or
186
187
        normalS : Ref to Normal squares
187
188
        """
188
189
 
 
190
        # IMPORTANT: we arrive here when all the checking about barriers
 
191
        # has been done. If we arrive here, checker CAN pass over here
 
192
 
189
193
        # ref to home square
190
194
        sqHome = normalS[self.initPos]
191
195
 
192
196
        # check if is there another checker in the square
193
197
        enemyCheckers = sq.getCheckers()
194
198
 
 
199
        diffColors = False
 
200
 
 
201
        # two checkers currently in this square
195
202
        if len(enemyCheckers) == 2:
196
 
            for enemyChk in enemyCheckers:
197
 
                # if not secure square, or is secure square but it is
198
 
                # my home, and not is stair o nirvana square, niam niam
199
 
                if (not sq.isSecure() or sqHome.getID() == sq.getID())\
200
 
                        and not sq.isStair() and not sq.isNirvana():
 
203
            # if not secure square, or is secure square but it is
 
204
            # my home, and not is stair o nirvana square, niam niam
 
205
            if (not sq.isSecure() or sqHome.getID() == sq.getID())\
 
206
                    and not sq.isStair() and not sq.isNirvana():
 
207
                for enemyChk in enemyCheckers:
201
208
                    if enemyChk.getColor() <> chk.getColor():
202
209
                        logging.warn("Checker from player %s is lunched by "\
203
210
                                     "checker from player %s",
207
214
                        # checker was lunched, go home!
208
215
                        self.toHome(enemyCheckers[0], normalS)
209
216
 
 
217
                        # if there is two checkers yet, lock the square
 
218
                        if len(enemyCheckers) == 2:
 
219
                            sq.setLock(True)
 
220
 
 
221
                        diffColors = True
 
222
 
210
223
                        return True
 
224
 
 
225
                # here nobody eats nobody, there is two checkers of same color
 
226
                # (or different color but in a secure square)
 
227
                if diffColors == False:
 
228
                    sq.setLock(True)
 
229
 
 
230
        # there is one checker only or two checkers
 
231
        # (same or different color) in a secure square
211
232
        return False
212
233
 
213
234
    def move(self, chk, dVal, normalS, stairS):
300
321
 
301
322
        # take the checker out from start pos and move into the target pos
302
323
        curSq.popChecker(chk)
 
324
 
 
325
        # add checker to the new square
303
326
        newSq.addChecker(chk)
 
327
 
304
328
        logging.info("checker from player %s moved to %s", self.getName(), \
305
329
                                                           str(chk.getPos()))
306
330
 
307
331
        # check if the checker eats another one with this movement
 
332
        # or if the square must be locked
308
333
        if self.checkIfNiamNiam(newSq, chk, normalS) == True:
309
334
            # glutton checker's team moves through 20 squares
310
335
            return 20