Add lastplaced

This commit is contained in:
s3lph 2022-10-05 06:50:33 +02:00
parent c6cf6db756
commit a1373bafbf
2 changed files with 26 additions and 2 deletions

View file

@ -48,8 +48,14 @@
<circle id="go-stone-{{ row }}-{{ col }}-empty" class="go-stone go-stone-empty go-stone-{{ colormap[player.uuid].name.lower() }}" data-row="{{ row }}" data-col="{{ col }}" cx="{{ col * 50 + 25 }}" cy="{{ row * 50 + 25 }}" r="20" />
{% elif field[row][col] == 1 %}
<circle id="go-stone-{{ row }}-{{ col }}-white" class="go-stone go-stone-white" cx="{{ col * 50 + 25 }}" cy="{{ row * 50 + 25 }}" r="20" />
{% if lastplaced[0] == row and lastplaced[1] == col and score is none %}
<rect class="go-territory go-territory-black" x="{{ col * 50 + 20 }}" y="{{ row * 50 + 20 }}" width="10" height="10" />
{% endif %}
{% elif field[row][col] == 2 %}
<circle id="go-stone-{{ row }}-{{ col }}-black" class="go-stone go-stone-black" cx="{{ col * 50 + 25 }}" cy="{{ row * 50 + 25 }}" r="20" />
{% if lastplaced[0] == row and lastplaced[1] == col and score is none %}
<rect class="go-territory go-territory-white" x="{{ col * 50 + 20 }}" y="{{ row * 50 + 20 }}" width="10" height="10" />
{% endif %}
{% elif field[row][col] == 5 %}
<circle id="go-stone-{{ row }}-{{ col }}-white-dead" class="go-stone go-stone-dead go-stone-white" cx="{{ col * 50 + 25 }}" cy="{{ row * 50 + 25 }}" r="20" />
{% elif field[row][col] == 6 %}
@ -91,8 +97,8 @@
{% endif %}
</div>
{% if game.is_completed %}
<a href="{{ baseurl }}/{{ me.uuid }}">Return to lobby</a>
{% if abandoned or score is not none %}
<a href="{{ baseurl }}/{{ player.uuid }}">Return to lobby</a>
{% else %}
<a href="{{ baseurl }}/{{ player.uuid }}/{{ game.uuid }}/play">Refresh</a>
{% endif %}

View file

@ -53,6 +53,7 @@ class GoPuzzle(Puzzle):
self._timer = None
self._tlock = Lock()
self._captures = [0, 0]
self._lastplaced = [-1, -1]
self._urlbase = '/'
def _gtp(self, command):
@ -189,6 +190,7 @@ Press Play! to play against GNU Go or invite a second player.
self._timer.start()
move = action['go-input-submit']
if move == 'Pass':
self._lastplaced = [-1, -1]
if self.current_player == FieldState.BLACK:
self.black_passed = True
else:
@ -205,12 +207,14 @@ Press Play! to play against GNU Go or invite a second player.
ret = self._gtp(f'play {player} {self.colnames[col]}{row+1}')
except RuntimeError:
return
self._lastplaced = [row, col]
if self.ai is None:
self.current_player = FieldState(3 - self.current_player.value)
elif self.gnugo is not None:
ai_color = self.colormap[self.ai.uuid].name.lower()
ai_resp = self._gtp(f'genmove_{ai_color}')
if 'pass' in ai_resp.lower():
self._lastplaced = [-1, -1]
if self.colormap[self.ai.uuid] == FieldState.BLACK:
self.black_passed = True
else:
@ -220,6 +224,19 @@ Press Play! to play against GNU Go or invite a second player.
else:
self.black_passed = False
self.white_passed = False
move = ai_resp.split()[1]
x = move[0]
y = move[1:]
print(x, y)
try:
row = int(y) - 1
col = self.colnames.index(x.upper())
if col is None:
self._lastplaced = [-1, -1]
else:
self._lastplaced = [row, col]
except:
self._lastplaced = [-1, -1]
self.update_field()
def update_field(self):
@ -271,6 +288,7 @@ Press Play! to play against GNU Go or invite a second player.
field=ser['field'],
territory=ser['territory'],
captures=ser['captures'],
lastplaced=self._lastplaced,
passed=[self.white_passed, self.black_passed],
boardsize=self.size.value,
colormap=self.colormap,