Skip to content

Instantly share code, notes, and snippets.

@uberto
Created February 14, 2018 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uberto/1d51d648d91a895b35fbb279d830c5da to your computer and use it in GitHub Desktop.
Save uberto/1d51d648d91a895b35fbb279d830c5da to your computer and use it in GitHub Desktop.
Python
def remove_string(self, string):
for point in string.stones:
# Removing a string can create liberties for other strings.
for neighbor in self.neighbor_table[point]:
neighbor_string = self._grid.get(neighbor)
if neighbor_string is None:
continue
if neighbor_string is not string:
self._replace_string(neighbor_string.with_liberty(point))
self._grid[point] = None
# Remove filled point hash code.
self._hash ^= zobrist.HASH_CODE[point, string.color]
Kotlin
fun removeString(string: GoString){
for (point in string.stones){
// Removing a string can create liberties for other strings.
for (neighbor: Point in neighbors(point)){
val neighborString = grid[neighbor] ?: continue
if (neighborString != string) {
updateStringOnGrid(neighborString.addLiberty(point))
}
}
grid[point] = null
// Remove filled point hash code.
zHash = zHash.xor(zobristTable.getValue(point))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment