Skip to content

Instantly share code, notes, and snippets.

@Ellahinator
Created August 26, 2022 15:09
Show Gist options
  • Save Ellahinator/b7e8b9c87b43b034613caf709fcbba8b to your computer and use it in GitHub Desktop.
Save Ellahinator/b7e8b9c87b43b034613caf709fcbba8b to your computer and use it in GitHub Desktop.
contract ExampleCar is Car {
constructor(Monaco _monaco) Car(_monaco) {}
function takeYourTurn(Monaco.CarData[] calldata allCars, uint256 ourCarIndex) external override {
Monaco.CarData memory ourCar = allCars[ourCarIndex];
uint othersBalance;
for (uint i; i < allCars.length; ++i) {
if(ourCarIndex != i) {
othersBalance += allCars[i].balance;
}
}
// if 2nd & near finish line, buy shell
if (ourCarIndex == 1 && ourCar.y >= 933 && ourCar.balance >= monaco.getShellCost(1)) monaco.buyShell(1);
// buy 20 acceleration right away
if (ourCar.y <= 1 && monaco.getAccelerateCost(20) <= 3030) monaco.buyAcceleration(20);
// buy cheap shells
if (monaco.getShellCost(1) <= 222) monaco.buyShell(1);
// if shelled, buy 10 acceleration if cheap
if (ourCar.speed == 1 && monaco.getAccelerateCost(10) <= 1111) {
monaco.buyAcceleration(10);
return;
}
// if other racers are poor, just buy accelerations
if (othersBalance <= 786) monaco.buyAcceleration(3);
// buy 2 cheap acceleration
if (monaco.getAccelerateCost(2) <= 369) monaco.buyAcceleration(2);
// buy more acceleration if rich towards end of race
if (allCars[0].y >= 600 && ourCar.balance >= 12222) monaco.buyAcceleration(2);
// if first and towards finishline, buy cheap shell if car behind us can afford.
if (ourCarIndex == 0 && ourCar.y >= 800 && allCars[1].balance >= monaco.getShellCost(1) && monaco.getShellCost(1) <= 666) monaco.buyShell(1);
// shell car in front of us
if (ourCarIndex != 0 && allCars[ourCarIndex - 1].speed > ourCar.speed) {
// buy no matter what price if near finish line
if(allCars[ourCarIndex - 1].y >= 800 || allCars[ourCarIndex - 1].speed >= 30) {
monaco.buyShell(1);
return;
}
// buy if cheap
else if (monaco.getShellCost(1) <= 500) {
monaco.buyShell(1);
return;
}
}
// if car behind us is faster than us and towards finish line, buy acceleration
if (ourCarIndex < 2 && allCars[ourCarIndex + 1].speed > ourCar.speed && ourCar.y >= 777) {
// buy 1-5 accelerations no matter what price
uint x = (allCars[ourCarIndex + 1].speed - ourCar.speed) % 5;
monaco.buyAcceleration(x + 1);
return;
}
// if towards finish line and we r shelled buy accelerations
if (ourCar.y >= 800 && ourCar.speed <=2 && ourCar.balance >= monaco.getAccelerateCost(3)) {
monaco.buyAcceleration(3);
return;
}
// if everyone still has decent money towards end, just buy acceleration
if (othersBalance + ourCar.balance >= 15000 && allCars[0].y >= 765) monaco.buyAcceleration(4);
// if im richer than the other 2 combined and we are towards the end, buy accelerations
if (ourCar.balance >= othersBalance && allCars[0].y >= 600) {
// if we are a lot more rich than other 2, buy 10 accelerations.
if(ourCar.balance / othersBalance >= 10 && ourCar.balance >= monaco.getAccelerateCost(10)) {
monaco.buyAcceleration(10);
} else monaco.buyAcceleration(2);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment