Question
Computer Network Security: Please help me ASAP... (PyCharm) Theme In the exercises of this chapter and the next, we will read data stored in different
Please help me ASAP...
(PyCharm)
Theme
In the exercises of this chapter and the next, we will read data stored in different formats. In both cases, the data tBasis of the exercise: the format used in the exercise
The format in this exercise is developed for describing situations onFile structure
Look at the above picture while reading this section.
File consists of headers and a set of chunks. More preciPlayers color : 1 character (M (black) or V (white))
Name length : 1 character (in range 1-9)
Name
: (name length) characterExercise
Implement the requested method to the object game. Chunkio
def load_game(self, input)
Creates a new Game object whicchunkio.py Submitted
A class for loading and saving the game situation from a file (not in this assignment).
In addition to t
Testing a sudden termination of the file (No need to examine - goes through if you just dont catch 10-exceptions, but let
And here is all the codes which are given us to use while doing the chunkIO.py and test.py:
1
2
3
from game import Game
from corrupted_chess_file_error import *
from player import Player
from piece import Piece
Afrom# The version information and the date are not used in this
# exercise
# ****************************************************class CorruptedChessFileError(Exception):
def __init__(self, message):
super(CorruptedChessFileError, self).__init__(message)import unittest
from io import String10
from chunkio import ChunkIO
from broken_reader import BrokenReader
from corrupted_chechunk_IO = ChunkIO()
#self.input_file = open(game.txt, r)
game = None
try:
game = chunk_10. load_game (self.input_file)
eself.input_file = BrokenReader(test_data, 26)
check_this = None
try:
Chunkio().load_game(self.input_file)
except CorruptedCheclass Player(object):
This class models a chess player.
II II II
# color of the player
WHITE = 0
BLACK = 1
def __init__(self,II III
return self._name
def get_color(self):
II III
Returns the color of this player.
@return: the color of this player.
ILIclass Piece(object):
This class models one single chess piece.
II III
Class constants listing all possible chess piece types.def --init__(self, owner, type):
Initializes a new Piece with the given owner and the given type.
@param owner: The player whdef _set_type(self, type ):
if type in [ Piece.KING, Piece.QUEEN, Piece.BISHOP, Piece. KNIGHT, Piece. ROOK, Piece.PAWN ]:
selfrom player import Player
from board import Board
class Game(object):
IIIIII
This class serves as a facade for the chess gameif self._white:
return self._white
raise ValueError(White player has not been added!);
def get_board(self):
II III
Returnsself._board = board
white = property( get_white )
black = property( get_black )
board = property ( get_board, set_board )from io import String10
class BrokenReader(String10):
-]
This class is used to artificially create problems. :)
The class wildef close(self):
If the raise_counter is set high enough, all data can be read.
In this case closing the stream will raise thclass Board(object):
II III
This class models a chess board.
def __init__(self):
Initiates a new empty board. C{board} is andef get_piece(self, column, row):
Returns the piece object located in the given coordinates.
@param column: the column of intreturn ord(row) - ord(1)
def --getitem__(self, key):
This method allows board to be used like a dictonary.
E.g. print boa
Thank you so much for your effort.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started