Beispiel #1
0
 def move(self, location, new_location):
     # TODO these validations can be moved one level higher
     validate_location_string(location)
     validate_location_string(new_location)
     if self[location] is None:
         raise EmptyLocationException
     if self[location].is_legal_move(location, new_location):
         self._execute_move(location, new_location)
Beispiel #2
0
def test_location_validator():
    nose.tools.ok_(not validate_location_string("H8"))
    nose.tools.ok_(not validate_location_string("f7"))
    nose.tools.assert_raises(InvalidLocationException,
                             validate_location_string, "DD6")
    nose.tools.assert_raises(InvalidLocationException,
                             validate_location_string, "K6")
    nose.tools.assert_raises(InvalidLocationException,
                             validate_location_string, "56")
    nose.tools.assert_raises(InvalidLocationException,
                             validate_location_string, "A9")
    nose.tools.assert_raises(InvalidLocationException,
                             validate_location_string, "d0")
Beispiel #3
0
 def is_location_empty(self, location):
     validate_location_string(location)
     return True if self._state[location] is None else False
Beispiel #4
0
 def __getitem__(self, location):
     validate_location_string(location)
     return self._state[location]