-
Notifications
You must be signed in to change notification settings - Fork 708
Max timer #1289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Max timer #1289
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5a833dd
Add max timer condition
jrouillard 7d84ace
Code rabit reviews
jrouillard d69c76b
Merge branch 'main' into max-timer
jrouillard 079b453
Merge branch 'main' into max-timer
jrouillard 68f570e
Merge branch 'main' into max-timer
jrouillard b727210
Merge branch 'main' into max-timer
jrouillard d5aaca7
change max timer to 2h
jrouillard eb64a3d
code reviews
jrouillard 66e5408
Merge branch 'main' into max-timer
jrouillard b56b43d
Merge branch 'main' into max-timer
jrouillard 2bbf0f3
remove files
jrouillard 014b505
Update resources/lang/en.json
jrouillard 7bc4b40
Change label
jrouillard 873ca13
Reviews
jrouillard f454fca
fix test
jrouillard 44b546a
remove useless comment
jrouillard e0386b5
remove unecessary characters
jrouillard 840453a
Merge branch 'main' into max-timer
jrouillard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import { WinCheckExecution } from "../../../src/core/execution/WinCheckExecution"; | ||
| import { GameMode } from "../../../src/core/game/Game"; | ||
| import { setup } from "../../util/Setup"; | ||
|
|
||
| describe("WinCheckExecution", () => { | ||
| let mg: any; | ||
| let winCheck: WinCheckExecution; | ||
|
|
||
| beforeEach(async () => { | ||
| mg = await setup("big_plains", { | ||
| infiniteGold: true, | ||
| gameMode: GameMode.FFA, | ||
| maxTimerValue: 5, | ||
| instantBuild: true, | ||
| }); | ||
| mg.setWinner = jest.fn(); | ||
| winCheck = new WinCheckExecution(); | ||
| winCheck.init(mg, 0); | ||
| }); | ||
|
|
||
| it("should call checkWinnerFFA in FFA mode", () => { | ||
| const spy = jest.spyOn(winCheck as any, "checkWinnerFFA"); | ||
| winCheck.tick(10); | ||
| expect(spy).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("should call checkWinnerTeam in non-FFA mode", () => { | ||
| mg.config = jest.fn(() => ({ | ||
| gameConfig: jest.fn(() => ({ | ||
| maxTimerValue: 5, | ||
| gameMode: GameMode.Team, | ||
| })), | ||
| percentageTilesOwnedToWin: jest.fn(() => 50), | ||
| })); | ||
| winCheck.init(mg, 0); | ||
| const spy = jest.spyOn(winCheck as any, "checkWinnerTeam"); | ||
| winCheck.tick(10); | ||
| expect(spy).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("should set winner in FFA if percentage is reached", () => { | ||
| const player = { | ||
| numTilesOwned: jest.fn(() => 81), | ||
| name: jest.fn(() => "P1"), | ||
| }; | ||
| mg.players = jest.fn(() => [player]); | ||
| mg.numLandTiles = jest.fn(() => 100); | ||
| mg.numTilesWithFallout = jest.fn(() => 0); | ||
| winCheck.checkWinnerFFA(); | ||
| expect(mg.setWinner).toHaveBeenCalledWith(player, expect.anything()); | ||
| }); | ||
|
|
||
| it("should set winner in FFA if timer is 0", () => { | ||
| const player = { | ||
| numTilesOwned: jest.fn(() => 10), | ||
| name: jest.fn(() => "P1"), | ||
| }; | ||
| mg.players = jest.fn(() => [player]); | ||
| mg.numLandTiles = jest.fn(() => 100); | ||
| mg.numTilesWithFallout = jest.fn(() => 0); | ||
| mg.stats = jest.fn(() => ({ stats: () => ({ mocked: true }) })); | ||
| // Advance ticks until timeElapsed (in seconds) >= maxTimerValue * 60 | ||
| // timeElapsed = (ticks - numSpawnPhaseTurns) / 10 => | ||
| // ticks >= numSpawnPhaseTurns + maxTimerValue * 600 | ||
| const threshold = | ||
| mg.config().numSpawnPhaseTurns() + | ||
| (mg.config().gameConfig().maxTimerValue ?? 0) * 600; | ||
| while (mg.ticks() < threshold) { | ||
| mg.executeNextTick(); | ||
| } | ||
| winCheck.checkWinnerFFA(); | ||
| expect(mg.setWinner).toHaveBeenCalledWith(player, expect.any(Object)); | ||
| }); | ||
|
|
||
| it("should not set winner if no players", () => { | ||
| mg.players = jest.fn(() => []); | ||
| winCheck.checkWinnerFFA(); | ||
| expect(mg.setWinner).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("should return false for activeDuringSpawnPhase", () => { | ||
| expect(winCheck.activeDuringSpawnPhase()).toBe(false); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.