179k views
1 vote
A board is a common concept that appears in many games such as Monopoly, Tic Tac Toe, Connect 4, Chess, and Checkers. For this assignment, you will be creating a simple board class that we will likely incorporate into future projects We are also going to go just a little bit beyond having a single board and allow the user to create multiple boards that they can then switch between.

An Example RunEnter the name of your board: Tic Tac ToeEnter the number of rows for your board: 3Enter the number of columns for your board: 3Enter the blank character to be used on your board: *Tic Tac Toe 0 1 20 * * *1 * * *2 * * *Select your action from the list below.1. Fill Spot2. Erase Spot3. Switch Board4. Create Board5. Quit

User Zergood
by
3.9k points

1 Answer

3 votes

Answer:

Kindly check the code screenshot in the attached images below.

Step-by-step explanation:

Program Files

filename: board.py

from typing import Iterable, List, TypeVar, Any

class Board:

def __init__(self, name:str, row:int, column:int, char:str):

self.name = name

self.row = row

self.column = column

self.char = char

def print_board(self, name:str, row:int, column:int, char:int):

name = name.strip()

print(name)

rowPrint = []

for i in range(int(column)+1):

if i == 0:

colTitle = ' '

else:

colTitle = colTitle + ' ' + str(i-1)

print(colTitle)

for i in range(int(row)):

rowPrint.append(str(i) + (' ' + str(char.strip())) * column)

print(rowPrint[i])

return rowPrint, colTitle

def erase_board(self, name:str, row:int, char:str, erase_row:int, erase_col:int, rowPrint:list, colTitle:list) -> list:

print(name)

print(colTitle)

for i in range(int(row)):

if i == erase_row:

newString = rowPrint[i][:((int(erase_col)+1)*2)] + str(char.strip()) + rowPrint[i][((int(erase_col)+1)*2)+1:]

rowPrint[i]=newString

print(rowPrint[i])

else:

print(rowPrint[i])

return rowPrint

def fill_board(self, name:str, row:int, fill_char:str, fill_row:int, fill_col:int, rowPrint:list, colTitle:list)->list:

print(name)

print(colTitle)

for i in range(int(row)):

if i == fill_row:

newFillString = rowPrint[i][:((int(fill_col)+1)*2)] + str(fill_char.strip()) + rowPrint[i][((int(fill_col)+1)*2)+1:]

rowPrint[i]= newFillString

print(rowPrint[i])

else:

print(rowPrint[i])

return rowPrint

def switch_action(self, name:str, colTitle:list, rowPrint:list)->None:

print(name)

print(colTitle)

for i in rowPrint:

print(i)

def new_board_save(self, row:int, column:int, char:str)->list:

rowPrint = []

for i in range(int(column) + 1):

if i == 0:

colTitle = ' '

else:

colTitle = colTitle + ' ' + str(i - 1)

for i in range(int(row)):

rowPrint.append(str(i) + (' ' + str(char)) * column)

return rowPrint, colTitle

A board is a common concept that appears in many games such as Monopoly, Tic Tac Toe-example-1
A board is a common concept that appears in many games such as Monopoly, Tic Tac Toe-example-2
User Kbariotis
by
3.8k points