Beispiel #1
0
 def test_after(self):
     # This isn't a valid sequence of moves, but it tests
     # out the board manipulation functions.
     self.assertEquals(
         terratri.boardToGrid('  _B '
                              '   L '
                              '  Rr '
                              '  .  '
                              '  .  '), terratri.after('nnEFfeSF'))
Beispiel #2
0
 def makeMove(self, move, user):
     # TODO: finish this, check for win, right player, etc...
     self.game.steps += move
     grid = terratri.after(self.game.steps)
     self.game.board = terratri.gridToBoard(grid)
     self.game.winner = terratri.winner(grid)
     self.game.whoseTurn = "" if self.game.winner else terratri.whoseTurn(self.game.steps)
     self.game.put()
     self.sendUpdate()
Beispiel #3
0
 def test_after(self):
     # This isn't a valid sequence of moves, but it tests
     # out the board manipulation functions.
     self.assertEquals(
         terratri.boardToGrid(
          '  _B '
          '   L '
          '  Rr '
          '  .  '
          '  .  '),
         terratri.after('nnEFfeSF'))
Beispiel #4
0
    def test_validSteps(self):
        self.assertEquals({
            'n': 'c2',
            'e': 'd1',
            'w': 'b1'
        }, terratri.validSteps('r', terratri.startGrid(), ''))

        # after an inital move of n, red changed the board, so can return south
        self.assertEquals(
            {
                'n': 'c3',
                'e': 'd2',
                'w': 'b2',
                's': 'c1',
                'x': 'end'
            }, terratri.validSteps('r', terratri.after('n'), 'n'))

        # after 1. ns:
        self.assertEquals({
            'S': 'c4',
            'E': 'd5',
            'W': 'b5'
        }, terratri.validSteps('b', terratri.after('ns'), 'ns'))

        # after 1. ns .. SN, red's choices are the same as on the first move
        self.assertEquals({
            'n': 'c2',
            'e': 'd1',
            'w': 'b1'
        }, terratri.validSteps('r', terratri.after('nsSN'), 'nsSN'))

        # but if 2. n, red cannot return south as it leaves the board unchanged
        self.assertEquals({
            'n': 'c3',
            'e': 'd2',
            'w': 'b2',
            'x': 'end'
        }, terratri.validSteps('r', terratri.after('nsSNn'), 'nsSNn'))
Beispiel #5
0
    def test_validSteps(self):
        self.assertEquals(
            {'n':'c2', 'e':'d1', 'w':'b1'},
            terratri.validSteps('r', terratri.startGrid(), ''))

        # after an inital move of n, red changed the board, so can return south
        self.assertEquals(
            {'n':'c3', 'e':'d2', 'w':'b2', 's':'c1', 'x':'end'},
            terratri.validSteps('r', terratri.after('n'), 'n'))

        # after 1. ns:
        self.assertEquals(
            {'S':'c4', 'E':'d5', 'W':'b5'},
            terratri.validSteps('b', terratri.after('ns'), 'ns'))

        # after 1. ns .. SN, red's choices are the same as on the first move
        self.assertEquals(
            {'n':'c2', 'e':'d1', 'w':'b1'},
            terratri.validSteps('r', terratri.after('nsSN'), 'nsSN'))

        # but if 2. n, red cannot return south as it leaves the board unchanged
        self.assertEquals(
            {'n':'c3', 'e':'d2', 'w':'b2', 'x':'end'},
            terratri.validSteps('r', terratri.after('nsSNn'), 'nsSNn'))