Skip to content

Commit

Permalink
fix() fix for 6 players
Browse files Browse the repository at this point in the history
  • Loading branch information
immortal-tofu committed Dec 7, 2023
1 parent 8b5d250 commit eeef132
Show file tree
Hide file tree
Showing 9 changed files with 275 additions and 179 deletions.
24 changes: 13 additions & 11 deletions contracts/CipherBomb.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ contract CipherBomb is Ownable, EIP712WithModifier {

function start() public onlyGameOpen {
require(numberOfPlayers >= MIN_PLAYERS, "Not enough player to start");
gameOpen = false;
gameRunning = true;
remainingWires = numberOfPlayers;
turnCurrentPlayer = players[0];
giveRoles();
emit GameStart();
bool roleDistributed = giveRoles();
if (roleDistributed) {
remainingWires = numberOfPlayers;
turnCurrentPlayer = players[0];
gameOpen = false;
gameRunning = true;
emit GameStart();
}
}

function join() public onlyGameOpen {
Expand Down Expand Up @@ -197,21 +199,21 @@ contract CipherBomb is Ownable, EIP712WithModifier {
}
}

function giveRoles() internal onlyRoleDealNeeded {
function giveRoles() internal onlyRoleDealNeeded returns (bool) {
uint8 badGuys = 2;
euint8[] memory positions = dealCards(badGuys, numberOfPlayers == 4 ? numberOfPlayers : numberOfPlayers - 1);
if (numberOfPlayers > 4) {
bool equal = TFHE.decrypt(TFHE.eq(positions[0], positions[1]));
if (equal) {
giveRoles();
return;
bool isCorrect = TFHE.decrypt(TFHE.ne(positions[0], positions[1]));
if (!isCorrect) {
return false;
}
}
for (uint8 i; i < numberOfPlayers; i++) {
ebool role = TFHE.and(TFHE.ne(positions[0], i), TFHE.ne(positions[1], i)); // If equal, role is bad guy (so = 0)

Check failure on line 212 in contracts/CipherBomb.sol

View workflow job for this annotation

GitHub Actions / ci

Line length must be no more than 120 but current length is 124
roles[players[i]] = role; // 1 = Nice guy / 0 = Bad guy
}
gameRoleDealNeeded = false;
return true;
}

function getRole(
Expand Down
1 change: 1 addition & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function getChainConfig(chain: keyof typeof chainIds): NetworkUserConfig {
switch (chain) {
case 'local':
jsonRpcUrl = 'http://localhost:8545/';
// jsonRpcUrl = 'http://52.47.200.198:8545/';
break;
case 'zama':
jsonRpcUrl = 'https://devnet.zama.ai/';
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"dotenv": "^16.0.3",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"ethers": "^6.4.0",
"ethers": "^6.9.0",
"fhevm": "^0.2.2",
"fhevmjs": "^0.1.3",
"fs-extra": "^10.1.0",
Expand Down Expand Up @@ -84,11 +84,13 @@
"fhevm:start": "docker run -i -p 8545:8545 -p 8546:8546 --rm --name fhevm ghcr.io/zama-ai/evmos-dev-node:v0.1.10",
"fhevm:stop": "docker rm -f fhevm",
"fhevm:restart": "fhevm:stop && fhevm:start",
"fhevm:faucet": "npm run fhevm:faucet:alice && sleep 5 && npm run fhevm:faucet:bob && sleep 5 && npm run fhevm:faucet:carol && sleep 5 && npm run fhevm:faucet:dave",
"fhevm:faucet": "npm run fhevm:faucet:alice && sleep 5 && npm run fhevm:faucet:bob && sleep 5 && npm run fhevm:faucet:carol && sleep 5 && npm run fhevm:faucet:dave && sleep 5 && npm run fhevm:faucet:eve && sleep 5 && npm run fhevm:faucet:oscar",
"fhevm:faucet:alice": "docker exec -i fhevm faucet $(npx hardhat task:getEthereumAddressAlice)",
"fhevm:faucet:bob": "docker exec -i fhevm faucet $(npx hardhat task:getEthereumAddressBob)",
"fhevm:faucet:carol": "docker exec -i fhevm faucet $(npx hardhat task:getEthereumAddressCarol)",
"fhevm:faucet:dave": "docker exec -i fhevm faucet $(npx hardhat task:getEthereumAddressDave)"
"fhevm:faucet:dave": "docker exec -i fhevm faucet $(npx hardhat task:getEthereumAddressDave)",
"fhevm:faucet:eve": "docker exec -i fhevm faucet $(npx hardhat task:getEthereumAddressEve)",
"fhevm:faucet:oscar": "docker exec -i fhevm faucet $(npx hardhat task:getEthereumAddressOscar)"
},
"dependencies": {
"@openzeppelin/contracts": "^4.9.3"
Expand Down
113 changes: 49 additions & 64 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 eeef132

Please sign in to comment.