Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For an exercise I'm supposed to write a code according to the task descriptions they have provided and produce the expected output according to the

For an exercise I'm supposed to write a code according to the task descriptions they have provided and produce the expected output according to the test cases. However I'm really confused with my code can someone modify my code not any other code so that it passes the test cases and please provide codes for the required methods so that when it is added to my code it runs without the need for any modifications from my end and i need this asap. shown below is my code : from collections import deque def load_board(filename): result = " " with open(filename) as f: print(f) for index, line in enumerate(f): if index == 0: result += ' '+' '.join([chr(alphabets + 65) for alphabets in range(len(line) - 1)]) + ' ' # the alphabetical column heading result += f"{19 - index:2d}" result += ' ' + ' '.join(line.strip()) + ' ' return result

def save_board(filename, board): with open(filename, "wt") as f: f.write(str(board))

from string import ascii_uppercase as letters class Board: #Dictionary created for the colours and the respected symbols points = {'E': '.', 'B': '@', 'W': 'O'} #Constructor def __init__(self,size=19,from_strings=None): #board assert 2

if from_strings: if type(from_strings) != list: raise AssertionError("input is not a list") if len(from_strings) != size: raise AssertionError("length of input list does not match size") for i in range(size): if type(from_strings[i]) != str: raise AssertionError("row " + str(i) + " is not a string") if len(from_strings[i]) != size: raise AssertionError("length of row " + str(i) + " does not match size") for j in range(size): if from_strings[i][j] not in ".@O": raise AssertionError("invalid character in row " + str(i)) #self.board=board #self.board= Board #self.from_strings=from_strings def get_size(self): #Returns the size of the grid created by the constructor return self.size

def __str__(self): # creating the grid padding = ' ' # Creating a variable with a space assigned so that it acts as a padding to the rows that have a single digit heading = ' ' + ' '.join(letters[:self.size]) # Alphabetical heading is created lines = [heading] # adding the alphabetical heading into a list named lines to which the rows will be added later for r, row in enumerate(self.grid): if len(self.grid) 9: # for rows 1 to 9 the single digits are aligned according to the first digit from the right of the two digit rows if (self.from_strings): line = f'{self.size - r} ' + ' '.join(self.from_strings[r]) else: line = f'{self.size - r} ' + ' '.join(self.points[x] for x in row) line = padding + line # adding the space using the variable padding to the row created lines.append(line) # adding the row to the list of rows else: # for the rows 10 onwards - as there is no requirement to add a padding it is not added here if (self.from_strings): line = f'{self.size - r} ' + ' '.join(self.from_strings[r]) else: line = f'{self.size - r} ' + ' '.join(self.points[x] for x in row) # creation of the row lines.append(line) # adding the newly created row to the list of rows return ' '.join(lines) def _to_row_and_column(self, coords): # destructure coordinates like "B2" to "B" and 2 alpha, num = coords colnum = ord(alpha) - ord('A') + 1 rownum = self.size - int(num) + 1 assert 1

def set_colour(self, coords, colour_name): rownum, colnum = self._to_row_and_column(coords) assert len(coords)==2 or len(coords)==3, "invalid coordinates" assert colour_name in self.points,"invalid colour name" self.grid[rownum - 1][colnum - 1] = colour_name

def get_colour(self, coords): rownum, colnum = self._to_row_and_column(coords) return self.grid[rownum - 1][colnum - 1]

def to_strings(self): #padding = ' ' lines = [] for r, row in enumerate(self.grid): if self.from_strings: lines.append(''.join(self.from_strings[r])) else: lines.append(''.join(self.points[x] for x in row)) return lines def to_integer(self): digit_colour="" for line in self.to_strings(): for character in line: if character=='.': character=0 elif character=='O': character=1 elif character=='@': character=2 character=str(character) digit_colour+=character return int(digit_colour,3)

# return ''.join(self.to_int[x] for line in self.grid for x in line)

def set_from_integer(self, integer_encoding): n = int(integer_encoding) list1 = [] p=[] m=[] t=[] while n != 0: rem = n % self.size #3 list1.append(rem) n = n // self.size#3 list1.reverse() list1=["." if item ==0 else item for item in list1] list1=["O" if item ==1 else item for item in list1] list1=["@" if item ==2 else item for item in list1] for i in range(0,len(list1),self.size):#3 p.append(list1[i:i+self.size])#3 #print(p) for x in p: m=''.join(map(str,x)) t.append(m) #print(Board(self.size,t)) self.from_strings=t

def fill_reaching(self,colour_name,reach_name, visited, r, c): new_list = [] new_list2 = [] for x in self.from_strings: for y in x: if y == ".": y = "E" elif y == "@": y = "B" elif y == "O": y = "W" new_list.append(y) for i in range(0, len(new_list), self.size): new_list2.append(new_list[i:i + self.size]) self.grid = new_list2 if r = self.size or c = self.size: #Checking whether the number of rows are within the size of the grid return False if visited[r][c] or self.grid[r][c] != colour_name:#Checking whether the number of columns are within the size of the grid return False if self.grid[r][c] == reach_name: return True visited[r][c] = True if self.fill_reaching(colour_name, reach_name, visited, r + 1, c): return True if self.fill_reaching(colour_name, reach_name, visited, r - 1, c): return True if self.fill_reaching(colour_name, reach_name, visited, r, c + 1): return True if self.fill_reaching(colour_name, reach_name, visited, r, c - 1): return True return False def reaching_empty_matrix(self): # Create a matrix of the same size as the board, filled with False values matrix = [[False for i in range(self.size)] for j in range(self.size)] #false for the empty grid # Iterate over the points on the board print(self.grid[1][0]) for i in range(self.size): for j in range(self.size): # If the current point is empty or an "O" point, perform a BFS from this point if self.grid[i][j] == "." or self.grid[i][j] == "O": queue = deque([(i, j)]) matrix[i][j] = True while queue: r, c = queue.popleft() for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)): new_r = r + dr new_c = c + dc # If the new point is within the bounds of the board and has not been visited, add it to the queue and mark it as visited if 0

def get_opposite_colour(self,colour): #returns the opposite colour of the given colour if colour=="B": return "W" elif colour=="W": return "B" else: raise ValueError("Invalid colour")

def get_neighbors(self,coords): #Returns a list of the neighbors of a point at the given coordinates directions=[(0,1),(0,-1),(1,0),(-1,0)] neighbors=[] for d in directions: r=coords[0]+d[0] c=coords[1]+d[1] if 0

TEST CASES------------------------------- #Task 1 b = Board(9) print(b) b = Board() print(b) print(b.get_size()) #Task 2 b = Board(5) b.set_colour("B1", "W") b.set_colour("C1", "B") b.set_colour("D1", "B") print(b) print(b.get_colour("C1")) b.set_colour("C1", "E") print(b) b.set_colour("C1", "G") #Task 3 b = Board(3, ["O.O", ".@.", "@O."]) print(b) print(b.to_strings()) c = Board(b.get_size(), b.to_strings()) print(str(b) == str(c)) #task 4 b = load_board("l19.txt") print(b) save_board("l19b.txt", b) #Task 5 b = Board(3, ["O.O", ".@.", "@O."]) print(b.to_integer()) l19 = load_board("l19.txt") print(l19.to_integer()) c = Board(3) c.set_from_integer(14676) print(c) d = Board(5) d.set_from_integer(1) print(d) #Task 6 b = Board(3, ["@O.", "OOO", ".O."]) print(b) visited = [[False] * 3 for i in range(3)] e = b.fill_reaching("W", "E", visited, 1, 1) print(e) print(visited) visited = [[False] * 3 for i in range(3)] e = b.fill_reaching("B", "E", visited, 0, 0) print(e) print(visited) visited = [[False] * 3 for i in range(3)] e = b.fill_reaching("W", "E", visited, 0, 0) print(e) print(visited) #Task 7 b = Board(3, ["O.O", ".@.", "@O."]) print(b.reaching_empty_matrix()) b = Board(3, ["O@O", ".O.", "@O."]) print(b.reaching_empty_matrix())

l19 = load_board("l19.txt") print(l19) e = l19.reaching_empty_matrix() for r in range(len(e)): for c in range(len(e[r])): if not e[r][c]: print((r, c)) #Task 8 l19 = load_board("l19.txt") print(l19) print(l19.is_legal()) l19.set_colour("E19", "E") print(l19.is_legal()) l19.set_colour("M9", "B") print(l19.is_legal()) print(l19) #Task 9 b = Board(9) b.set_from_integer(123480537448700274361724717496626688035) print(b) print(b.is_legal()) b.clear_colour("B") print(b) print(b.is_legal()) #Task 10 b = Board(9) b.set_from_integer(123480537448700274288778724742285115148) print(b) b.play_move("B", "D5") print(b) b.play_move("W", "E1") print(b) b.play_move("B", "E7") print(b) b.play_move("W", "E5") print(b) #Task 11 b = Board(9) b.set_from_integer(618162000026984091812681185497885) print(b) print(b.score()) b.set_colour("I5", "E") print(b) print(b.score()) b.set_colour("E2", "E") print(b) print(b.score()) #Task 12 g = Game(9, "Tom", "Harald") print(g) g.play_move("B", "G3") print(g) g.play_move("W", "C6") g.play_move("B", "F6") g.play_move("W", "E3") g.play_move("B", "D7") g.play_move("W", "G4") g.play_move("B", "F4") g.play_move("W", "G5") g.play_move("B", "F5") g.play_move("W", "F3") g.play_move("B", "H3") g.play_move("W", "H7") g.play_move("B", "F2") g.play_move("W", "F8") g.play_move("B", "D3") g.play_move("W", "E4") g.play_move("B", "D4") g.play_move("W", "D6") g.play_move("B", "E5") g.play_move("W", "E7") g.play_move("B", "H5") g.play_move("W", "G6") g.play_move("B", "B5") g.play_move("W", "C5") g.play_move("B", "C4") g.play_move("W", "B6") g.play_move("B", "B4") g.play_move("W", "F7") g.play_move("B", "H6") g.play_move("W", "H4") g.play_move("B", "I4") g.play_move("W", "G7") g.play_move("B", "I3") g.play_move("W", "A5") g.play_move("B", "A4") g.play_move("W", "A6") g.play_move("B", "D5") g.play_move("W", "I6") g.play_move("B", "I5") g.play_move("W", "I7") g.play_move("B", "E6") g.play_move("W", "D8") g.play_move("B", "E2") g.play_move("W", "C7") g.play_pass("B") g.play_pass("W") print(g.get_board()) print(g)

g = Game(9) g.play_move("B", "C5") g.play_move("W", "D5") g.play_move("B", "D6") g.play_move("W", "E6") g.play_move("B", "D4") g.play_move("W", "E4") g.play_move("B", "E5") g.play_move("W", "F5") g.play_move("B", "F6") g.play_move("W", "D5") print(g) print(g.get_board()) g.play_move("B", "E5")

description on the code Parts that need to be checked and modified according to the description Task 1 In the file go.py, implement a class Board representing a square Go board.

The constructor should take an optional integer parameter size with a default value of 19 to indicate the size of the board. The size must be between 2 and 26, inclusive. If this is not the case, raise an AssertionError with the error message "Illegal board size: must be between 2 and 26.". The constructor should create a square board of the given size with all points initialised as empty.

Implement the method get_size(self) that returns the size of the board.

Implement the method __str__(self) to convert a Board to a string that when printed gives an "ASCII art" representation of the board with coordinates marked with letters and numbers along the columns and rows. Click on the "Expand" button below for an example. Use the following characters to represent the points on the board:

empty: "."

black: "@"

white: "O"

Test case expected output A B C D E F G H I 9 . . . . . . . . . 8 . . . . . . . . . 7 . . . . . . . . . 6 . . . . . . . . . 5 . . . . . . . . . 4 . . . . . . . . . 3 . . . . . . . . . 2 . . . . . . . . . 1 . . . . . . . . .

A B C D E F G H I J K L M N O P Q R S 19 . . . . . . . . . . . . . . . . . . . 18 . . . . . . . . . . . . . . . . . . . 17 . . . . . . . . . . . . . . . . . . . 16 . . . . . . . . . . . . . . . . . . . 15 . . . . . . . . . . . . . . . . . . . 14 . . . . . . . . . . . . . . . . . . . 13 . . . . . . . . . . . . . . . . . . . 12 . . . . . . . . . . . . . . . . . . . 11 . . . . . . . . . . . . . . . . . . . 10 . . . . . . . . . . . . . . . . . . . 9 . . . . . . . . . . . . . . . . . . . 8 . . . . . . . . . . . . . . . . . . . 7 . . . . . . . . . . . . . . . . . . . 6 . . . . . . . . . . . . . . . . . . . 5 . . . . . . . . . . . . . . . . . . . 4 . . . . . . . . . . . . . . . . . . . 3 . . . . . . . . . . . . . . . . . . . 2 . . . . . . . . . . . . . . . . . . . 1 . . . . . . . . . . . . . . . . . . .

19 Task 2 Implement a method set_colour(self, coords, colour_name) that changes the colour at the coordinates given by coords. coords must be a string consisting of an upper case letter specifying the column followed by an integer specifying the row. colour_name must be one of the strings "E" (for empty), "B" (for black), "W" (for white). If coords is not a string of length 2 or 3, raise an AssertionError with the string "invalid coordinates". If column or row are out of range, raise an AssertionError with the message "column out of range" or "row out of range", respectively. If the colour name is invalid, raise an AssertionError with the message "invalid colour name".

Implement a method get_colour(self, coords) that returns the colour of the point at the given coordinates. Coordinates and colour names are as described above. Check for valid coordinates as above.

Test case expected output

A B C D E 5 . . . . . 4 . . . . . 3 . . . . . 2 . . . . . 1 . O @ @ .

B A B C D E 5 . . . . . 4 . . . . . 3 . . . . . 2 . . . . . 1 . O . @ .

Traceback (most recent call last): [...] AssertionError: invalid colour name

Task 3 Extend the constructor of class Board to accept an additional optional argument from_strings. If present, this argument must be a list of strings where each string represents a row of the board with the character encoding used in the __str__() method, but without the intervening spaces and the coordinate letters. For example, for a board of size 19, from_strings must be a list of 19 strings, each having exactly 19 characters from the set ".@O". Check the validity of from_strings and raise AssertionErrors with the following messages for invalid inputs (the letter x should indicate the row coordinate of the invalid row):

"input is not a list" "length of input list does not match size" "row x is not a string" "length of row x does not match size" "invalid character in row x" Implement a method to_strings(self) that returns a representation of the board as a list of strings in the same format as that accepted by the __init__() method.

Expected output

A B C 3 O . O 2 . @ . 1 @ O .

['O.O', '.@.', '@O.'] True Task 4

Outside the class, define a function load_board(filename) that takes as an argument the name of a text file, reads a Go position from that file and returns a Board object representing the position. The file must contain one line for each row of the board, using the characters ".", "@", and "O" as above to represent the colours.

Define a function save_board(filename, board) that takes as arguments a filename and a Board object and saves the position to a text file in the same format as that accepted by load_board().

should print

A B C D E F G H I J K L M N O P Q R S 19 . . . . @ @ @ . O O . . @ . O O O . O 18 @ O O @ O @ . . @ O @ O . . . @ @ . @ 17 @ O . . @ O . O O O O O . O O O O O @ 16 . . @ @ . O O . @ . . O @ O . @ . O . 15 O . @ . @ . O @ . O O @ @ O . . O @ O 14 O . . . O O O @ . @ @ . . . @ . O @ @ 13 . . @ O @ . . @ . . O O O . @ . @ . . 12 . . @ @ . @ @ @ . . . @ O . O . . . @ 11 @ O . . @ . @ @ @ @ O . . @ O O O @ O 10 @ . . O . @ @ O @ O O @ @ . @ . O @ . 9 @ O O O . . @ O . . @ @ O @ @ @ . O O 8 @ @ O @ . O O O . @ . O @ . @ @ @ . @ 7 @ . O . O @ O O . O O . @ O @ . . @ O 6 @ . . . O @ @ O O @ . @ @ . . O . O . 5 O O @ @ . . O @ @ . @ . @ . O @ @ O . 4 @ . O . . O O . @ O @ O @ O O . @ @ . 3 @ @ O O @ . O . @ . O @ . @ O @ O . . 2 . . . O O @ @ O . @ O . O . @ O O @ . 1 @ @ . @ O . @ @ . . @ O O O O O @ @ @

and create a file l19b.txt which is identical to l19.txt.

Task 5

In class Board, define two new methods:

to_integer(self) returns an integer encoding of the position

set_from_integer(self, integer_encoding) sets the colours of all points of the board according to the given integer_encoding. This does not change the size of the board!

If we replace the colours of the points of the Go board by digits (empty = 0, white = 1, black = 2) and concatenate all rows of the board to a single row of digits, we get a ternary number that can then be converted to an integer. The method to_integer(self) is supposed to do exactly that. For example, the 33 board used in the example for Task 3 looked like this:

A B C 3 O . O 2 . @ . 1 @ O .

Hint: To convert an integer n to ternary representation, as required by set_from_integer(), note that you get the last digit by computing nmod3. You get the next digit by computing n/3mod3 and so on. For example, heres how to get the last two digits of the ternary representation of 7473: 7473mod3=0. 7473/3=2491. 2491mod3=1.

should print

7473 208168199381979984699478633344862770286522453884530548425639456820927419612738015378525648451698519643907259916015628128546089888314427129715319317557736620397247064840935 A B C 3 @ . @ 2 . O . 1 O @ .

A B C D E 5 . . . . . 4 . . . . . 3 . . . . . 2 . . . . . 1 . . . . O Task 6

In the Board class, define a method fill_reaching(self, colour_name, reach_name, visited, r, c) that receives the following parameters:

colour_name: the name of the colour ("E", "B", or "W") of the chain to be marked

reach_name: the name of a colour to be tested for reachability

visited: a matrix (list of lists) of Booleans of the same size as the board

r, c: the row and column number indexed from 0, i.e. 0, 0 is the top left corner

The method executes the flood fill algorithm, starting from the position given by r and c, to mark all points of colour colour_name that are connected to the starting position by a path of colour colour_name moving only vertically and horizontally. The method modifies the matrix visited: marking a point is defined as setting the corresponding element in visited to True. Some elements of visited may be True to begin with the corresponding grid points are treated as if they were of a colour different from colour_name. The method must not modify the Board object.

In addition to marking all visited points, the method returns True if the starting point reaches the colour specified in reach_name (see rule #3 in the background information) and False otherwise.

should print A B C 3 @ O . 2 O O O 1 . O .

True [[False, True, False], [True, True, True], [False, True, False]] False [[True, False, False], [False, False, False], [False, False, False]] False [[False, False, False], [False, False, False], [False, False, False]]

Task 7

In the Board class, define a method reaching_empty_matrix(self) that returns a matrix (list of lists) of Booleans of the same size as the board. An element of this matrix is True if the corresponding point on the board is either empty or reaches empty and False otherwise. The method must not modify the board.

should print

[[True, True, True], [True, True, True], [True, True, True]] [[True, False, True], [True, True, True], [True, True, True]] A B C D E F G H I J K L M N O P Q R S 19 . . . . @ @ @ . O O . . @ . O O O . O 18 @ O O @ O @ . . @ O @ O . . . @ @ . @ 17 @ O . . @ O . O O O O O . O O O O O @ 16 . . @ @ . O O . @ . . O @ O . @ . O . 15 O . @ . @ . O @ . O O @ @ O . . O @ O 14 O . . . O O O @ . @ @ . . . @ . O @ @ 13 . . @ O @ . . @ . . O O O . @ . @ . . 12 . . @ @ . @ @ @ . . . @ O . O . . . @ 11 @ O . . @ . @ @ @ @ O . . @ O O O @ O 10 @ . . O . @ @ O @ O O @ @ . @ . O @ . 9 @ O O O . . @ O . . @ @ O @ @ @ . O O 8 @ @ O @ . O O O . @ . O @ . @ @ @ . @ 7 @ . O . O @ O O . O O . @ O @ . . @ O 6 @ . . . O @ @ O O @ . @ @ . . O . O . 5 O O @ @ . . O @ @ . @ . @ . O @ @ O . 4 @ . O . . O O . @ O @ O @ O O . @ @ . 3 @ @ O O @ . O . @ . O @ . @ O @ O . . 2 . . . O O @ @ O . @ O . O . @ O O @ . 1 @ @ . @ O . @ @ . . @ O O O O O @ @ @

(1, 4) (10, 12)

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

please provide the rectified version of my code with the required modifications and also provide the codes that are needed which was stated therefore please add them all in my code. I'm very confused with my code right now so please add the modifications and additions to my code and nothing else cz every single time I asked I didn't get it based on my code where it could be added so please provide the code in accordance with mine the program is in python

Task 8 In the Board class, define a method is_legal(self) that returns True if the position on the board is legal and False otherwise (see Background Information for the definition of a legal position). A B C DEFGHIJKLMN OPQRS 19....@@.00..@.000.0 18@00@0@..@@0@0...@@.@ 17@0.@0.00000.00000@ 16..@@.00.@..0@0.@.0. 150.@.@.0@.00@@0..0@0 140..0000@.@@...@.0@@@ 13..@0@..@..000.@.@.. 12..@@.@@@...@0.0...@ 11@0..@.@@@@0..@000@0 10@..0.@@0@00@@.@.0@. 9@000..@0..@@@@@@.00 8@@0@.000.@.0@.@@@.@ 7@.0.0@00.00.@0@..@0 6@..0@@00@.@@..0.0. 500@@..0@@.@.@.0@@0. 4@.0..00.@0@0@@00.@@. 3@@00@.0.@.0@.@0@0.. 2...00@@0.@0.0.@00@. 1@@.@0.@@..@@00000@@@@ Task 10: In the Board class, define a method play_move(self, colour_name, coords ) that plays a move according rule \#7 (see Background Information). For coords and colour_name, see Task 2. If the point at the given coordinates is not empty, raise an AssertionError with message "illegal move: point not empty" .should print Task 12: It is now time to put everything together. Implement a class Game that simulates a game of Go according to the Logical Rules (see Background Information). The constructor should take three optional arguments: - an integer specifying the board size, default 19 - a string with the name of the player playing black, default "Black" - a string with the name of the player playing white, default "White" When converted to a string, a Game object should appear in one of the following forms, depending on the state of the game: Here, [White] stands for the name of the player playing white, [Black] stands for the name of the player playing black, [colour ] is one of black, white and [score] is a positive integer. B+ indicates that Black won, W+ indicates that White won, the letter R indicates a win by resignation and the term jigo is used for a tie. Implement a method get_board(self) that returns a Board object with the current position. Implement a method get_score(self) that returns the score difference, (white - black). If the game has not yet ended, raise an AssertionError with the message "game still in progress". Implement methods - play_move(self, colour_name, coords) - to play a move - play_pass(self, colour_name) - to pass - play_resign(self, colour_name) - to resign - play_move(self, colour_name, coords) - to play a move - play_pass(self, colour_name) - to pass - play_resign(self, colour_name) - to resign For coords and colour_name, see the corresponding methods of class Board above. All methods should raise AssertionError s with the message "invalid move: game has ended" if the game has already ended and with the message "invalid move: it 's [colour] 's turn" if the wrong player tries to make a move. If a move would repeat an earlier grid colouring (see rule \#6), raise an AssertionError with message "invalid move: positional superko rule violated". should print A BCDEFGHI 9 80.0 7..0.00000 60000@@0@0 50@0@@@0@@ 4@@@@.@00@ 3...@...@@@ 2....@@... 1 should print A B C DEFGHI 9.... 8 7 6...@0@... 5..@0.0... 4...@0.... 3. 2 1 [...] AssertionError: invalid move: positional superko rule violated 4. Clearing a colour is the process of emptying all points of that colour that don't reach empty. 5. Starting with an empty grid, the players alternate turns, starting with Black. 6. A turn is either a pass; or a move that doesn't repeat an earlier grid colouring. 7. A move consists of colouring an empty point one's own colour; then clearing the opponent colour, and then clearing one's own colour. 8. The game ends after two consecutive passes. 9. A player's score is the number of points of their colour, plus the number of empty points that reach only their colour. 10. The player with the higher score at the end of the game is the winner. Equal scores result in a tie. Go is usually played on a wooden board where the points are marked by a grid of lines. It can be played on rectangular grids of different sizes without otherwise changing the rules. Beginners usually start on a 99 board. Rule 2 Colouring a point black or white is achieved by placing a stone of that colour on the board on the intersection of two lines (they don't go in the boxes!). Colouring a point empty means removing the stone. To illustrate rule 3 , let's look at a 99 board with some stones on it, i.e. some points coloured black or white. The black point marked with a triangle reaches empty because there is a path of (vertically or horizontally adjacent) black points, marked with circles, to a point coloured empty (marked with a square). The black point marked with a triangle reaches empty because there is a path of (vertically or horizontally adjacent) black points, marked with circles, to a point coloured empty (marked with a square). The white point below the triangle does not reach empty. By following a path of white points only vertically or horizontally, you only ever reach black, not empty. Legal Positions A legal position is a position in which every point coloured black or white reaches empty. The example above is not a legal position because there are points coloured white that don't reach empty. (Can you see how we had to fiddle with the image because Go software wouldn't let us create an illegal position ;-)?) It is a consequence of the rules that every valid move creates a legal position. This is because according to rule \#7, both colours are cleared, removing any stones that don't reach empty. Fun fact: the total number of legal positions on a 1919Go board is about 2.0816810170. The exact number was computed by John Trump in 2016. In the above position, clearing black doesn't change anything because all black points reach empty. Clearing white results in the following position, which is legal: Consider this example: The three black points all reach empty according to the definition: From each of them there is a path of black points to the point F9, which is empty. After White plays F9, Black's three stones don't reach empty any more, so they areremoved: Note that the definition of reaching (rule \#3) taks about a path of vertically or horizontally adjacent points. This is visualised on the Go board by following the lines. The two points B8 and F8 are not adjacent to the chain of three black stones. Here's another example for the application of rule \#7. Consider this position: Here, all black stones reach empty, namely the point marked by the triangle. If Black now plays on that point, rule \#7 states that first White is cleared (which results in removing nothing, because each white stone reaches empty) and then Black is cleared. This removes all black stones because none of them reach empty after the move: and then Black is cleared. This removes all black stones because none of them reach empty after the move: So this move is suicide for Black, and it is allowed in the Logical Rules of Go which we are using in this assignment. Note that in the rulesets used by most humans playing Go, suicide is forbidden. Rule 6 prohibits repeating an earlier grid colouring. Consider the following situation with Black to play: If Black plays at the position marked by the triangle, carefully consider how rule \#7 is applied. First, the black stone is placed (the point is coloured black). Then white is cleared according to rule \#4. This removes the white stone at C7, since it does no longer reach empty. Finally, black is cleared. Note that since the white stone has been removed, the newly placed stone reaches empty, so nothing is removed and this move by Black is not suicide. The resulting position is this: Next, it is White's turn to play. If White were to play at C7, the black stone at D7 would be removed and we would reach the same board position as before. This would violate rule \#6 because this move would repeat an earlier grid colouring. So this move is illegal by rule \#6. If, howeyer, White and Black first play two moves elsewhere on the board, then white could capture back at C7 because the overall position ("grid colouring") would be different. Note that rule 6 forbids repeating any earlier grid colouring, not just the immediately preceding one. (That's why Go experts call it the positional superko rule, but don't worry about that.) Here is an example of how a game of Go might have ended. First, we count black's points: Black has 21 stones and two empty areas (22-24 and 25-43) that reach only black, so their total score is 43. Now let's count white: Black has 21 stones and two empty areas (22-24 and 25-43) that reach only black, so their total score is 43 . Now let's count white: They have 19 stones plus one empty area for a total of 38. Overall, black wins by 5 points. In records of Go games, it is common notation to write this result as " B+5 ". Note that rule \# 9 states that empty areas only count if they reach only one colour. If an empty area of the board reaches both black and white, it doesn't count for either player. Consider the following position: The three points marked with triangles reach both black and white, so they are considered neutral, i.e. they are not included in either black's or white's score

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

9th Edition

0135188148, 978-0135188149, 9781642087611

More Books

Students also viewed these Databases questions

Question

Has each action got a clear and measurable outcome?

Answered: 1 week ago

Question

Have you eliminated jargon and unexplained acronyms?

Answered: 1 week ago