Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Introduction to the game of Surakarta Surakarta is, according to some reports, a traditional Indonesian board game. It is similar to chequers, but has some

Introduction to the game of Surakarta Surakarta is, according to some reports, a traditional Indonesian board game. It is similar to chequers, but has some unique twists. Your goal, in this project, is to implement the functionality required to ensure that only legal moves are allowed by the Python-based version of Surakarta. The Rules of Surakarta (adapted from Cyningstan):

The board consists of a six-by-six grid of lines, with two concentric circular tracks at each corner, as shown below. Pieces are placed on the points where lines intersect. Each player starts with twelve pieces (black or white tokens) that are placed on the intersections nearest that player.

A six-by-six Surakarta board with pieces in starting positions. Note: initially, we will work with a more compact four-by-four version of the Surakarta board, with a single circular track at each corner, as shown below. On this board, each player starts with only four pieces placed on the intersections nearest to that player. However, the functions you implement should also work for a six-by-six version of the board. A four-by-four Surakarta board with pieces in starting positions. The Rules of Surakarta (adapted from Cyningstan):

Players decide at random who moves first. In a turn, a player must make one of two types of move (passing is not allowed):

A normal move, in which a player moves one of their pieces from one intersection to an adjacent intersection, horizontally, vertically, or diagonally. Pieces may not jump over other pieces, and only one piece may occupy an intersection at any point in time. The circular tracks around each corner may not be used for normal moves.A valid normal move in Surakarta. The black piece at intersection (1, 0) in the left board has been moved to the previously empty intersection (2, 1), as shown on the right board. Had the destination intersection not been empty, this would not have been a valid normal move.

A capture move, in which a player slides a piece along a straight line, around a circular track, and then further along a straight line, until it lands on an opposing piece, which is then removed from the board. Pieces making a capture move may move more than one intersection during such a move, but may not jump over other pieces. Note that a capture move must use at least one of the circular tracks, and may use more than one. Update: A capture move can start and/or end on the edge of the board; that is, it can move along a straight line of length zero!A valid capture move in Surakarta. The white piece at intersection (1, 3) in the left board has captured the black piece at intersection (2, 1). The route it traces to do so is up to the top of the board, around the circular track, and then right to the target piece. Had this route contained any other pieces (black or white), or had it not traversed one of the circular tracks, then this move would not have been a valid capture move.

A player wins when they have captured all of their opponent's pieces.

To make it simpler to define test cases for your function, the board state may be defined in terms of an N-by-N string specifying the state of the board; eg, for the four-by-four game, the string 'xxxx........oooo' specifies the initial board state. Tip: To make the relationship between a string and the corresponding board state clearer, it may help to represent the string as follows: 'xxxx' + '....' + '....' + 'oooo' Remember that + concatenates two strings. In this representation 'x' represents a black piece, 'o' represents a white piece, and '.' represents an empty location. A string is unlikely to be the most convenient internalrepresentation for the board state: a list of lists (a nested list) is a better choice. You have been provided with three functions to assist with converting between board strings and board states; and drawing graphical representations of the board, which may assist with developing and debugging your code and test cases:

The function get_board_state(board_string) will return a board state based on the specified board string. Board strings must be 16 or 36 characters long, and the dimension of the board state returned will be four-by-four or six-by-six respectively.

>>> from reference import get_board_state >>> get_board_state('xxxx........oooo') [['x', '.', '.', 'o'], ['x', '.', '.', 'o'], ['x', '.', '.', 'o'], ['x', '.', '.', 'o']] Note that you can obtain the value of a specific location from a board state (ie, black, white, or empty): the first index will be the x-coordinate (column) and the second index will be the y-coordinate (row). >>> from reference import get_board_state >>> board = get_board_state('xxxx........oooo') >>> board[0][1] '.' >>> board[1][3] 'o'

The function get_board_string(board_state) will return a board string representation of the specified board state.

>>> from reference import get_board_string

>>> get_board_string([['x', '.', '.', 'o'], ['x', '.', '.', 'o'], ['x', '.', '.', 'o'], ['x', '.', '.', 'o']])

'xxxx........oooo'

Question: Write a function make_move_normal(board_string, start,end) that takes as input a string representation of the current board state, a tuple representing a the initial position of the piece to be moved (start), and a tuple representing the end position (end) the piece is to be moved to. This function will validate if the move is valid and if so, execute the move. The function should return a string representation of the board reflecting the position of the pieces after the move if the move is valid, or None if the move is invalid. Assumptions: Capture moves need not be considered for the purpose of this task (ie, they would be deemed invalid). i.e

>>> print(make_move_normal('xxxx........oooo', (0, 0), (0, 1))) '.xxxx.......oooo' >>> print(make_move_normal('xxxx........oooo', (0, 0), (2, 2))) None

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_2

Step: 3

blur-text-image_3

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

Upgrading Oracle Databases Oracle Database New Features

Authors: Charles Kim, Gary Gordhamer, Sean Scott

1st Edition

B0BL12WFP6, 979-8359657501

More Books

Students also viewed these Databases questions