[Solved] CSCI301 Assignment 3 in Python

$25

File Name: CSCI301_Assignment_3_in_Python.zip
File Size: 282.6 KB

SKU: [Solved] CSCI301 Assignment 3 in Python Category: Tag:
5/5 - (1 vote)

In this assignment, your task is programming a blockchain system simulating a Tic-tac-toe game between two parties (Alice and Bob).

A game is played in the following order.

  1. The game is initiated by putting the genesis block in both Alice and Bobs computers.
  2. The game always starts with Alice. Hence, Alice will create the first block with its choice on the board and send it to Bob.
  3. Bob validates the received block from Alice and stores it on his computer. He creates a new block with his choice on the board and sends it to Alice.
  4. Alice verifies the received block from Bob and stores it on her computer. She creates a new block with her choice on the board and sends it to Bob.
  5. 3 and 4 are repeated until all spaces on the board taken. It is not necessary to compute who is the winner of the game.

The followings are the requirements to simulate the game explained above.

[The Genesis Block]

Both players have the initial block (i.e., the genesis block) to start their play. The initial block, Block0.json, for both Alice and Bob is set as follows:

{} TxID: 0,Hash: This is the genesis block.,Nonce: 0,Transaction: []

Figure 1. Block0.json

[The Requirements for the Other Blocks]

At each turn, a player (e.g., Alice) who takes the turn creates a new block in the JSON format and send the new block to the other player (e.g., Bob) who plays tictac-toe together. The format of each block as follows:

{

TxID: <TxID>,

Hash: <Hash> ,

Nonce: <Nonce>,

Transaction: <Transaction>

}

The entities in the above block are computed as follows:

  1. <TxID> is the block index which increased by 1. For example, the <TxID> of the first block (Block1.json) is 1. The <TxID> of the second block (Block2.json) is 2.

  1. <Hash> is the output of the SHA256 hash which takes as input the content of the last block, <The the last block>.
  1. <Nonce>: The player increases the value of <Nonce> from 0 by 1 until the value of the hash output is less than 2248. You can keep <Nonce> in the integer format.

SHA256(<The current block>) < 2248

HINT: You may need to convert <The current block> to bytes so that they can be taken as input for SHA256. You can convert them using String.encode() method. (e.g., str(a).encode() where a is <The current block> in the string format.)

  1. <Transaction> is the choice of the player in its turn. It contains the player name and its choice of the space on the tic-tac-toe board (e.g., [Alice,5]). To make your code simple, assume that Alice and Bob take a random empty space in their turn.

Alice and Bob keep each block in a separate file (Block0.json, Block1.json, , Block9.json) in their local storage. Before each player executes their turn, it must check that the block received is valid.

[Lets Play a Game]

Assume that we use the following grid to play a tic-tac-toe game.

1 2 3
4 5 6
7 8 9

Before starting a game, make sure that Block0.json (i.e., the genesis block) is located in both Alice and Bobs storage.

  • File list in Alices storage: Block0.json
  • File list in Bobs storage: Block0.json

The first block (Block1.json) is generated by Alice as follows.

{

TxID: 1,

Hash:5adf16531bf399b20f0059b6cc97d54a28d06581f8c522 d6a756ce7b15af3ec3,

Nonce: 86,

Transaction: [Alice,5]

}

Note that in your program, Alice must randomly choose a space on the board. Then, Alice saves the block in her storage and sends it to Bob. Once Bob receives the block, Bob validates the received block and save it to its storage.

At this stage, Alice and Bob will have two blocks in their folders.

  • File list in Alices storage: Block0.json, Block1.json
  • File list in Bobs storage: Block0.json, Block1.json

Then, Bob creates the following block and send it to Alice:

{

TxID: 2,

Hash:00bbbd0551e4e39b42d375e00656b6fdf930a32f6278a11

64de44425a573545c,

Nonce: 437,

Transaction: [Bob,1]

}

Note that in your program, Bob must randomly choose a space among the spaces not taken previously. Alice also checks the Nonce is correct and store the received block in the storage. So, that both will have Block2.json in their folders.

  • File list in Alices storage: Block0.json, Block1.json, Block2.json
  • File list in Bobs storage: Block0.json, Block1.json, Block2.json

Each game will continue until all spaces on the board are taken. It is not necessary to check who is the winner.

[Exchanging blocks]

Make the players exchange blocks online. You can use the PubNub package to implement this in Python. You also can use the other program (e.g., a sock program) to exchange blocks for the game.

Note: Your program does not need to exchange a whole block. Instead, it can send the necessary information to reconstruct the block on each side and set Alice and Bob to create the block using the received information.

For example, instead of the whole block, Alice sends the following:

1; 5adf16531bf399b20f0059b6cc97d54a28d06581f8c522d6a756ce7b15af3ec3;86;5

for the first block. Since all information is given to Bob, he can reconstruct the first block 1 (Block1.json) in the JSON format on his side.

[Marks]

  • Block generation process implementation. (30 marks)
  • Block validation process implementation. (10 marks)
  • The other basic requirements of the system (e.g., implementation of a tictac-toe game and handling JSON format.) (30 marks)
  • Implementation of blocks exchange protocol (20 marks)
  • Report explaining the requirements to execute your program and the expected outcome of your program.
  • (10 marks)

[Submission]

Make a folder named Assignment3 and include Programs for Alice and Bob.

  • The history of one of the completed games (e.g., Block0.json, Block1.json, , and json)
  • Please include the student numbers and names of all group members.

Compress the Assignment3 folder using a zip program to create [one of the group members surnames]_Assignment3.zip.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CSCI301 Assignment 3 in Python[Solved] CSCI301 Assignment 3 in Python
$25