repaired some attack related code
This commit is contained in:
parent
4c1bcf370f
commit
125bbd6575
@ -29,3 +29,7 @@ The key size is determined by the variable `KEY_SIZE` in `random_primes.js`. Thi
|
|||||||
variable dictates the size of _each_ prime used in the modulus, so the total key size
|
variable dictates the size of _each_ prime used in the modulus, so the total key size
|
||||||
is twice this value. Recommend selecting one of 512, 1024, or 2048. In fact, I recommend
|
is twice this value. Recommend selecting one of 512, 1024, or 2048. In fact, I recommend
|
||||||
selecting 512 if you want the program to run in less than 3-5 business days.
|
selecting 512 if you want the program to run in less than 3-5 business days.
|
||||||
|
|
||||||
|
Key generation will still take some time. The browser may tell you the tab is not
|
||||||
|
responding, but just wait and it'll be fine eventually. If not, short-circuit the
|
||||||
|
`generate_safe_prime` function in `random_primes.js` to just return a normal prime.
|
||||||
|
@ -57,7 +57,6 @@ function updateMapDom() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
showStrengths();
|
showStrengths();
|
||||||
|
|
||||||
showRemainingReinforcements();
|
showRemainingReinforcements();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,14 +147,6 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
el.addEventListener("click", (ev) => {
|
el.addEventListener("click", (ev) => {
|
||||||
let region = ev.target.closest(".node").dataset.name;
|
let region = ev.target.closest(".node").dataset.name;
|
||||||
game.us.sendReinforce(region);
|
game.us.sendReinforce(region);
|
||||||
|
|
||||||
if (game.isPregame()) {
|
|
||||||
game.us.endTurn();
|
|
||||||
|
|
||||||
if (game.allReinforcementsPlaced()) {
|
|
||||||
game.incrementState();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ document.addEventListener("ACT", async (ev) => {
|
|||||||
game.setReady(data.author, data.ready);
|
game.setReady(data.author, data.ready);
|
||||||
} else {
|
} else {
|
||||||
// Throw out our own packets
|
// Throw out our own packets
|
||||||
if (data.author === game.us.id) {
|
if (!game.isPlaying() && data.author === game.us.id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,6 +53,14 @@ class Strength {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
transparentUpdate(value) {
|
||||||
|
this.cipherText.update(new Ciphertext(this.cipherText.pubKey, value, 0n));
|
||||||
|
|
||||||
|
if (this.assumedStrength !== null) {
|
||||||
|
this.assumedStrength += value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
update(cipherText) {
|
update(cipherText) {
|
||||||
if (this.cipherText === null) {
|
if (this.cipherText === null) {
|
||||||
this.cipherText = cipherText;
|
this.cipherText = cipherText;
|
||||||
@ -130,7 +138,7 @@ export class Region {
|
|||||||
claim(player, cipherText) {
|
claim(player, cipherText) {
|
||||||
this.owner = player;
|
this.owner = player;
|
||||||
this.strength.update(cipherText);
|
this.strength.update(cipherText);
|
||||||
this.strength.assumedStrength = 1;
|
this.strength.assumedStrength = 1n;
|
||||||
}
|
}
|
||||||
|
|
||||||
reinforce(cipherText) {
|
reinforce(cipherText) {
|
||||||
|
@ -109,8 +109,8 @@ export class Player {
|
|||||||
*/
|
*/
|
||||||
reinforce(data) {
|
reinforce(data) {
|
||||||
if (!verifyRegions(data.verification, this.paillierPubKey)) {
|
if (!verifyRegions(data.verification, this.paillierPubKey)) {
|
||||||
console.log("Failed to verify Protocol 4.5!");
|
console.log("Failed to verify reinforcements!");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let regionName of Object.keys(data.regions)) {
|
for (let regionName of Object.keys(data.regions)) {
|
||||||
@ -169,11 +169,11 @@ export class Player {
|
|||||||
|
|
||||||
this.totalStrength += 1;
|
this.totalStrength += 1;
|
||||||
|
|
||||||
if (game.isPlaying()) {
|
if (game.isPregame()) {
|
||||||
this.reinforcementsPlaced += 1;
|
game.us.endTurn();
|
||||||
|
|
||||||
if (this.reinforcementsPlaced === this.reinforcementsAvailable) {
|
if (game.allReinforcementsPlaced()) {
|
||||||
this.turnPhase = PHASE_ATTACK;
|
game.incrementState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -187,7 +187,9 @@ export class Player {
|
|||||||
async act(data) {
|
async act(data) {
|
||||||
if (this.turnPhase === PHASE_REINFORCE) {
|
if (this.turnPhase === PHASE_REINFORCE) {
|
||||||
if (data.regions !== undefined) {
|
if (data.regions !== undefined) {
|
||||||
if (this.reinforce(data)) {
|
if (this === game.us) {
|
||||||
|
this.reinforcementsPlaced += 1;
|
||||||
|
} else if (this.reinforce(data)) {
|
||||||
this.reinforcementsPlaced += 1;
|
this.reinforcementsPlaced += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,9 +252,12 @@ export class Player {
|
|||||||
defenderStrength <= 0 ||
|
defenderStrength <= 0 ||
|
||||||
defenderStrength > Math.min(2, defender.strength)
|
defenderStrength > Math.min(2, defender.strength)
|
||||||
) {
|
) {
|
||||||
|
console.log("waiting");
|
||||||
defenderStrength = await defender.owner.getDefense();
|
defenderStrength = await defender.owner.getDefense();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(defenderStrength);
|
||||||
|
|
||||||
/* How do Risk attacks work?
|
/* How do Risk attacks work?
|
||||||
- Offender signs 1-3 armies, defender signs 1-2 armies
|
- Offender signs 1-3 armies, defender signs 1-2 armies
|
||||||
- Both roll respective dice
|
- Both roll respective dice
|
||||||
@ -289,11 +294,12 @@ export class Player {
|
|||||||
let defenderResult = defenderRolls.pop();
|
let defenderResult = defenderRolls.pop();
|
||||||
|
|
||||||
if (offenderResult > defenderResult) {
|
if (offenderResult > defenderResult) {
|
||||||
defender.strength -= 1;
|
defender.strength.transparentUpdate(-1n);
|
||||||
} else {
|
} else {
|
||||||
offender.strength -= 1;
|
offender.strength.transparentUpdate(-1n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle region capture.
|
||||||
if (defender.strength === 0) {
|
if (defender.strength === 0) {
|
||||||
defender.strength = offenderRolls.length + 1;
|
defender.strength = offenderRolls.length + 1;
|
||||||
offender.strength -= offenderRolls.length + 1;
|
offender.strength -= offenderRolls.length + 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user