rebalance game, make bots weaker, improve leaderboard

This commit is contained in:
evanpelle
2024-10-17 21:01:10 -07:00
parent 96b4ffe649
commit 29f1b398ee
5 changed files with 35 additions and 29 deletions
+3 -3
View File
@@ -166,11 +166,11 @@
* single player mode DONE 10/12/2024
* single player select map DONE 10/12/2024
* implement private game DONE 10/15/2024
* private game can select map DONE 10/16/2024
* Test on android DONE 10/17/2024
* NPC has relations
* private game shows how many players joined
* private game can select map
* BUG: memory leak: game not deleted when leaving game
* optimize sendBoat function
* Test on android
* NPC more likely to accept alliance fewer alliance player has
* better NPC relation logic
* surface NPC relations
+2 -2
View File
@@ -97,7 +97,7 @@
186
],
"name": "England",
"strength": 1
"strength": 3
},
{
"coordinates": [
@@ -129,7 +129,7 @@
220
],
"name": "France",
"strength": 1
"strength": 2
},
{
"coordinates": [
+18 -7
View File
@@ -7,7 +7,7 @@ import {ClientID} from '../../../core/Schemas';
interface Entry {
name: string
position: number
score: number
score: string
isMyPlayer: boolean
}
@@ -49,7 +49,7 @@ export class Leaderboard extends LitElement implements Layer {
.map((player, index) => ({
name: player.name(),
position: index + 1,
score: player.numTilesOwned(),
score: formatPercentage(player.numTilesOwned() / this.game.numLandTiles()),
isMyPlayer: player == myPlayer
}));
@@ -66,7 +66,7 @@ export class Leaderboard extends LitElement implements Layer {
this.players.push({
name: myPlayer.name(),
position: place,
score: myPlayer.numTilesOwned(),
score: formatPercentage(myPlayer.numTilesOwned() / this.game.numLandTiles()),
isMyPlayer: true,
})
}
@@ -91,7 +91,7 @@ export class Leaderboard extends LitElement implements Layer {
left: 10px;
z-index: 9999;
background-color: rgba(30, 30, 30, 0.7); /* Added transparency */
padding: 15px;
padding: 10px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
border-radius: 10px;
max-width: 300px;
@@ -116,10 +116,10 @@ export class Leaderboard extends LitElement implements Layer {
}
.myPlayer {
font-weight: bold;
font-size: 1.4em;
font-size: 1.5em;
}
.otherPlayer {
font-size: 1.2em;
font-size: 1.3em;
}
tr:nth-child(even) {
background-color: rgba(44, 44, 44, 0.5); /* Made alternating rows slightly transparent */
@@ -150,7 +150,7 @@ export class Leaderboard extends LitElement implements Layer {
<tr>
<th>Rank</th>
<th>Player</th>
<th>Score</th>
<th>Owned</th>
</tr>
</thead>
<tbody>
@@ -181,4 +181,15 @@ export class Leaderboard extends LitElement implements Layer {
get isVisible() {
return !this._hidden;
}
}
function formatPercentage(value: number): string {
const perc = value * 100
if (perc < .01) {
return "0%"
}
if (perc < .1) {
return (perc).toPrecision(1) + '%'
}
return perc.toPrecision(2) + '%';
}
+9 -12
View File
@@ -77,14 +77,6 @@ export class DefaultConfig implements Config {
// speed = mag
if (attacker.isPlayer() && defender.isPlayer()) {
if (attacker.type() == PlayerType.Bot && defender.type() == PlayerType.Human) {
mag *= 1.2
}
if (attacker.type() == PlayerType.Bot && defender.type() == PlayerType.FakeHuman) {
mag *= 1.5
}
if (attacker.type() == PlayerType.Human && defender.type() == PlayerType.Bot) {
mag *= .8
}
@@ -101,7 +93,7 @@ export class DefaultConfig implements Config {
}
} else {
return {
attackerTroopLoss: mag / 2,
attackerTroopLoss: attacker.type() == PlayerType.Bot ? mag / 10 : mag / 5,
defenderTroopLoss: 0,
tilesPerTickUsed: within(this.startTroops(attacker.info()) / (attackTroops * 5), .2, 3) * Math.max(10, speed / 1.5)
}
@@ -133,14 +125,18 @@ export class DefaultConfig implements Config {
return 10000
}
if (playerInfo.playerType == PlayerType.FakeHuman) {
return 10000
return 25000
}
return 10000
return 25000
}
maxTroops(player: Player): number {
let max = Math.sqrt(player.numTilesOwned()) * 3000 + 50000
return Math.min(max, 2_000_000)
const troops = Math.min(max, 2_000_000)
if (player.type() == PlayerType.Bot) {
return troops
}
return troops * 2
}
troopAdditionRate(player: Player): number {
@@ -150,6 +146,7 @@ export class DefaultConfig implements Config {
const ratio = 1 - (player.troops() / max)
toAdd *= ratio
toAdd *= .5
// console.log(`to add ${toAdd}`)
if (player.type() == PlayerType.FakeHuman) {
+3 -5
View File
@@ -19,7 +19,7 @@ export class FakeHumanExecution implements Execution {
private rejected: Set<Player> = new Set<Player>
private isTraitor = false
private relations = new Map<Player, number>()
constructor(private playerInfo: PlayerInfo, private cell: Cell, private strength: number) {
this.random = new PseudoRandom(simpleHash(playerInfo.id))
@@ -131,10 +131,8 @@ export class FakeHumanExecution implements Execution {
handleAllianceRequests() {
for (const req of this.player.incomingAllianceRequests()) {
if (this.rejected.has(req.requestor())) {
continue
}
if (req.requestor().numTilesOwned() > this.player.numTilesOwned() * 2) {
if (req.requestor().numTilesOwned() > this.player.numTilesOwned() * 2) {
req.accept()
continue
}