From 0f840de8f507c3f1f0d4b513c7ba8c258f97e0d9 Mon Sep 17 00:00:00 2001 From: Abhinav Upadhyay Date: Tue, 25 Dec 2018 13:01:22 +0530 Subject: [PATCH 1/2] Simplify get_go_string() in Board implementation We could simply return the value from self._grid.get(point) rather than checking for None, since if it is None we are returning None. --- code/dlgo/goboard_slow.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/code/dlgo/goboard_slow.py b/code/dlgo/goboard_slow.py index e64fb219..becb0838 100644 --- a/code/dlgo/goboard_slow.py +++ b/code/dlgo/goboard_slow.py @@ -124,10 +124,7 @@ def get(self, point): # <1> return string.color def get_go_string(self, point): # <2> - string = self._grid.get(point) - if string is None: - return None - return string + return self._grid.get(point) # <1> Returns the content of a point on the board: a Player if there is a stone on that point or else None. # <2> Returns the entire string of stones at a point: a GoString if there is a stone on that point or else None. # end::board_utils[] From 9d71094cc4ad375e0b7aa0cf368547a120a71cf3 Mon Sep 17 00:00:00 2001 From: Abhinav Upadhyay Date: Wed, 26 Dec 2018 13:39:53 +0530 Subject: [PATCH 2/2] Simply get_go_string() in other Board implementations as well --- code/dlgo/goboard.py | 5 +---- code/dlgo/goboard_fast.py | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/code/dlgo/goboard.py b/code/dlgo/goboard.py index 10faef88..4b432a9f 100644 --- a/code/dlgo/goboard.py +++ b/code/dlgo/goboard.py @@ -155,10 +155,7 @@ def get_go_string(self, point): Returns None if the point is empty, or a GoString if there is a stone on that point. """ - string = self._grid.get(point) - if string is None: - return None - return string + return self._grid.get(point) def __eq__(self, other): return isinstance(other, Board) and \ diff --git a/code/dlgo/goboard_fast.py b/code/dlgo/goboard_fast.py index 81546b72..1f4ac055 100644 --- a/code/dlgo/goboard_fast.py +++ b/code/dlgo/goboard_fast.py @@ -232,10 +232,7 @@ def get_go_string(self, point): Returns None if the point is empty, or a GoString if there is a stone on that point. """ - string = self._grid.get(point) - if string is None: - return None - return string + return self._grid.get(point) def __eq__(self, other): return isinstance(other, Board) and \