Skip to content

Commit

Permalink
updated ships
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-gai committed Aug 18, 2023
1 parent c0842b5 commit d38cf5c
Show file tree
Hide file tree
Showing 5 changed files with 613 additions and 392 deletions.
36 changes: 35 additions & 1 deletion contracts/Battleship.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract Battleship {
bool public player1Ready;
bool public player2Ready;

uint8 public constant BOARD_SIZE = 10;
uint8 public constant BOARD_SIZE = 4;
uint8 public player1ShipsHit;
uint8 public player2ShipsHit;

Expand Down Expand Up @@ -76,6 +76,40 @@ contract Battleship {
return shipCount == 17;
}

function verifyShipsPlacedFHE(bytes[4][4] calldata _ships) public view returns (bool) {
euint8 shipCount = TFHE.asEuint8(0);
for (uint8 i = 0; i < BOARD_SIZE; i++) {
for (uint8 j = 0; j < BOARD_SIZE; j++) {
shipCount = TFHE.add(shipCount, TFHE.asEuint8(TFHE.eq(TFHE.asEuint8(_ships[i][j]), TFHE.asEuint8(2))));
}
}
return TFHE.decrypt(shipCount) == 6;
}

// function verifyShipsPlacedFHE3(bytes[3][3] calldata _ships) public view returns (uint8) {
// euint8 shipCount = TFHE.asEuint8(0);
// for (uint8 i = 0; i < 3; i++) {
// for (uint8 j = 0; j < 3; j++) {
// ebool b = TFHE.eq(TFHE.asEuint8(_ships[i][j]), TFHE.asEuint8(2));
// shipCount = TFHE.add(shipCount, TFHE.cmux(b, TFHE.asEuint8(1), TFHE.asEuint8(0)));
// }
// }
// return TFHE.decrypt(shipCount);

// // TFHE.req(TFHE.eq(shipCount, TFHE.asEuint8(6)));
// // return true;
// // return shipCount == 17;
// }

// function verifyShipsPlacedFHE4(bytes calldata encryptedValue) public view returns (uint8) {
// euint8 shipCount = TFHE.asEuint8(encryptedValue);
// return TFHE.decrypt(shipCount);

// // TFHE.req(TFHE.eq(shipCount, TFHE.asEuint8(6)));
// // return true;
// // return shipCount == 17;
// }

function attack(uint8 _x, uint8 _y) public onlyPlayers {
require(gameReady, "Game not ready");
require(!gameEnded, "Game has ended");
Expand Down
1 change: 1 addition & 0 deletions output.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"ethers": "^6.4.0",
"fhevm": "^0.1.6",
"fhevm": "^0.1.8",
"fhevmjs": "^0.0.5",
"fs-extra": "^10.1.0",
"hardhat": "^2.12.2",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d38cf5c

Please sign in to comment.