Compare commits
No commits in common. "main" and "Game-Polish" have entirely different histories.
main
...
Game-Polis
|
|
@ -1 +0,0 @@
|
||||||
{"version":1,"dirMtimeMs":1795818542664.5647,"goals":[]}
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 85 KiB After Width: | Height: | Size: 341 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -548,8 +548,7 @@
|
||||||
"voice": "Djed Spence",
|
"voice": "Djed Spence",
|
||||||
"convo": [
|
"convo": [
|
||||||
"terry",
|
"terry",
|
||||||
"victor",
|
"victor"
|
||||||
"bernie"
|
|
||||||
],
|
],
|
||||||
"speech": {
|
"speech": {
|
||||||
"intro": [
|
"intro": [
|
||||||
|
|
@ -587,11 +586,6 @@
|
||||||
"citySheet": "classic",
|
"citySheet": "classic",
|
||||||
"bio": "Let's take a break on a warm summer day to spend time playing games!",
|
"bio": "Let's take a break on a warm summer day to spend time playing games!",
|
||||||
"voice": "Street Fighter 6 - Crimson Viper",
|
"voice": "Street Fighter 6 - Crimson Viper",
|
||||||
"convo": [
|
|
||||||
"croc",
|
|
||||||
"nadia",
|
|
||||||
"smasher"
|
|
||||||
],
|
|
||||||
"speech": {
|
"speech": {
|
||||||
"intro": [
|
"intro": [
|
||||||
"juliet-intro-01",
|
"juliet-intro-01",
|
||||||
|
|
@ -624,11 +618,6 @@
|
||||||
"startingTechs": [],
|
"startingTechs": [],
|
||||||
"citySheet": "mayan",
|
"citySheet": "mayan",
|
||||||
"bio": "Mystical Powers and a knack for games.",
|
"bio": "Mystical Powers and a knack for games.",
|
||||||
"voice": "Antonio Bandaras",
|
|
||||||
"convo": [
|
|
||||||
"brad",
|
|
||||||
"jerry"
|
|
||||||
],
|
|
||||||
"speech": {
|
"speech": {
|
||||||
"intro": [
|
"intro": [
|
||||||
"balam-intro-01",
|
"balam-intro-01",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
# Spelling Bee — words forced onto the ANSWER list even though the frequency
|
|
||||||
# data missed them. One per line: `WORD` (familiar tier) or `WORD core`.
|
|
||||||
# Must be ENABLE words that can appear in a hive (4+ letters, no S, ≤7 distinct
|
|
||||||
# letters). Rerun `node tools/buildBeeWords.js` after editing.
|
|
||||||
UPROOT
|
|
||||||
POUTING
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,55 +0,0 @@
|
||||||
# Spelling Bee — words that never count as ANSWERS (they're still accepted as
|
|
||||||
# Rare Finds if ENABLE has them). One word per line; `#` starts a comment.
|
|
||||||
# Rerun `node tools/buildBeeWords.js` after editing.
|
|
||||||
|
|
||||||
# ── Names / places whose ENABLE meaning is obscure ─────────────────────────────
|
|
||||||
ABBA ABIGAIL AGGIE ALAMEDA ALAN ALAND ALBA ALEC ALEXANDER ALEXIA ALINE ALMA
|
|
||||||
ALTHEA AMIN AMIR AMRITA ANDROMEDA ANGELICA ANIL ANNA APOLLO APPEL ARGENT ARIEL
|
|
||||||
AXEL BACH BARNY BARRET BAYARD BAZAR BECK BECKET BEDELL BELIER BENEDICT BENNET
|
|
||||||
BENNY BENJAMIN BERG BERLIN BERTHA BETH BETHEL BETTA BILLIE BLAIN BOBBY BOLLING
|
|
||||||
BONITA BONNE BORA BOUTON BOWYER BRAD BRANT BREE BRIT BRITT BROOKING BUFFY BURG
|
|
||||||
BURKE BURNIE BURTON CALLAN CAMPAGNA CANDIDA CARBO CARINA CARL CARLIN CARLING
|
|
||||||
CARMAN CARMEN CARNEY CARR CARTER CATE CATLIN CATTIER CHANG CHAO CHAPMAN CHARLEY
|
|
||||||
CHARLIE CHARRY CHEVY CHICO CICELY CICERO CLARENCE CLARY CLIFT CLINE COBB COBBY
|
|
||||||
CODDING COLIN COLLEEN CONCHA CONN CONNER CONTE CORBY CORNEL CORRIE CORY COTE
|
|
||||||
COUCHER COULTER CULVER CURR CURRAN CURRIE CYPRIAN DAHL DAPHNE DAVY DEVON DEWAR
|
|
||||||
DEXTER DIDO DOMINICK DONA DONNA DOTY DUMA DURNING EMMET ERICA EUGENIA FARO
|
|
||||||
FLETCHER FRANKLIN FREEDMAN FRITZ GABY GALATEA GAULT GEMMA GENET GENEVA
|
|
||||||
GEORGETTE GERMAN GILBERT GLORIA GODDING GOODMAN GRAHAM GRANNIE GURNEY HAKEEM
|
|
||||||
HAKIM HALBERT HENRY HILLER HOGG HOLLAND HONG JACKY JAEGER JAKE JANE JENNY JERRY
|
|
||||||
JILL JOHN JOHNNY JORDAN KANE KATA KELLY KENT KERN KERRY KHAN KRAFT LAIRD LAMBERT
|
|
||||||
LANDAU LANG LANGLEY LAURA LAZAR LEARY LEAVY LENO LEONE LEVIN LEVY LICHT LING
|
|
||||||
LINN LOGAN LORIMER LOTTE LOUIE LOWE LUCE LUNA MACK MADELEINE MADONNA MAGDALEN
|
|
||||||
MAGDALENE MALKIN MAMIE MARC MARCEL MARIA MARTIN MARYJANE MATILDA MATT MAUD MAYA
|
|
||||||
MEDINA MELTON MERLE META MICK MIGNON MIGNONNE MILO MINA MOIRA MOLLIE MONTE
|
|
||||||
MONTEITH MORA MORGAN MORGEN MOROCCO MORT MOTT MULLEN MULLER MUNGO MURPHY MURRY
|
|
||||||
NANCE NANCY NANNIE NAPOLEON NATAL NELLIE NELLY NEMA NETTY NEVE NEWTON NICOL
|
|
||||||
OTTO PANDORA PARKER PATTEN PATTIE PEDRO PEERY PERI PERRON PERRY PETER PHOEBE
|
|
||||||
PILAR POLLACK POLLOCK POMFRET PONCE POULTER PRENTICE PUGH PURI QUINTA QUINTIN
|
|
||||||
RALPH RANCE RAND REGINA REYNARD RHEA RICK RICKEY RIDLEY RITTER RITZ ROBBIN ROLF
|
|
||||||
ROMANO ROMEO ROQUE RUDD RUTH TABER TABOR TAKA TAMMIE TAMMY TELFER TELFORD TERRY
|
|
||||||
THORPE TIFFANY TIMOTHY TOBY TOMMY TONEY TONY TORI TROY TURK TYNE ULTIMA URANIA
|
|
||||||
VAIL VALENCIA VANDYKE VERA VICTORIA VITA WARNER WATERMAN WAUGH WEBER WEINER
|
|
||||||
WELCHER WYNN XENIA YAGER BAILEY BURNIE
|
|
||||||
|
|
||||||
# ── Offensive, vulgar or adult ──────────────────────────────────────────────────
|
|
||||||
ANAL ANUS BITCH BITCHY BONDAGE BONER BOOB BOOBY CLIT COCK COCKY COON CRAP DAGO
|
|
||||||
DICK DICKEY DICKIE DICKY DILDO DYKE FAGGOT FAGGOTRY FART FUCK FUCKER GOOK HOMO
|
|
||||||
HONKY HOOKER HUMP HYMEN JIZZ KIKE KRAUT NIGGER NIGGARD PECKER PENIS PIMP PISS
|
|
||||||
POOP PORN PORNO PRICK PUBIC RAPE RAPER RAPED RAPING RETARD SLUT TURD TWAT
|
|
||||||
VAGINA VULVA WANK WENCH WETBACK WHORE WOP YID BALLING HOOCH BOOZE BOOZER
|
|
||||||
CUNT ORGY
|
|
||||||
|
|
||||||
# ── Web/abbreviation junk that ranks high on frequency lists ────────────────────
|
|
||||||
ACTA AERO ALFA ANON BAHT CAIN COCA COLE DONG DYER EXEC FUJI HAHA HOLT HOWE JEUX
|
|
||||||
KIRK LAMA LIMA LITE METH MOLY MONY NAZI NITE PARA PHAT PLAT POOH PROG TATE TELE
|
|
||||||
THRU YANG YUAN MANA
|
|
||||||
ACYL ARCO BABA BARM BATT BENE BOCK BODE BOGY BUNN BUTE CAKY CAPO CAVY CHEZ CINE
|
|
||||||
COLY CONY COWY DADA DEXY DIDY DOGY DOIT DURA DURO EELY EIDE ELMY EXON EYRE EYRY
|
|
||||||
FICO FILA FLEY FOGY FORA GAPY GELD GIGA GIRO GUID HAUT HELO HOLM HOMY HORA HOYA
|
|
||||||
ILLY JOKY KEMP KINO LAKH LAKY LIMY LINY LIRE LOCA LOGY LORY MAAR MANO MAZY MITY
|
|
||||||
MOPY MUNI MUON NANA NIXY NOME OLDY ORBY PADI PALY PARR PATY PILY PIMA PINY PIPY
|
|
||||||
POCO RIAL RIEL RIMY ROPY ROTA ROTO RULY TAIN TING TODY TOWY TRAD TROP TUFF TUNG
|
|
||||||
TYPY VIDE VINY WADY WANY WICH WINY
|
|
||||||
TITANIA MICRA AMICI MARGE LEGER GLEBE NICOTIANA TITIAN MANHATTAN
|
|
||||||
TITTY LATED RALLYE LINAC VELOCE FACIA DERRY RILEY COCO CALIF AVION
|
|
||||||
|
|
@ -287,7 +287,6 @@ export const MANIFEST = {
|
||||||
// first-player(5). Frame order documented in AzulData.js. A placeholder
|
// first-player(5). Frame order documented in AzulData.js. A placeholder
|
||||||
// sheet ships; vectors draw when absent.
|
// sheet ships; vectors draw when absent.
|
||||||
azul: [sheet('azul-tiles', 'assets/images/azul-tiles.png', 96, 96)],
|
azul: [sheet('azul-tiles', 'assets/images/azul-tiles.png', 96, 96)],
|
||||||
mexicantrain: [{ type: 'audio', key: 'mt-dominoes-shuffle', path: 'assets/speech/dominoes-shuffle.mp3' }],
|
|
||||||
tickettoride: [sheet('ttr-cards', 'assets/images/tickettoride-cards.png', 270, 390)],
|
tickettoride: [sheet('ttr-cards', 'assets/images/tickettoride-cards.png', 270, 390)],
|
||||||
gofish: [sheet('gofish-cards', 'assets/images/gofish-cards.png', 270, 390)],
|
gofish: [sheet('gofish-cards', 'assets/images/gofish-cards.png', 270, 390)],
|
||||||
oldmaid: [sheet('oldmaid-cards', 'assets/images/oldmaid-cards.png', 270, 390)],
|
oldmaid: [sheet('oldmaid-cards', 'assets/images/oldmaid-cards.png', 270, 390)],
|
||||||
|
|
@ -312,11 +311,6 @@ export const MANIFEST = {
|
||||||
sheet('jello-items', 'assets/images/jello-items.png', 132, 132),
|
sheet('jello-items', 'assets/images/jello-items.png', 132, 132),
|
||||||
image('bg-puddingmonsters-menu', 'assets/images/background-jello.png'),
|
image('bg-puddingmonsters-menu', 'assets/images/background-jello.png'),
|
||||||
],
|
],
|
||||||
// Chinese Checkers art is all procedural (ChineseCheckersArt.js); only the
|
|
||||||
// chinese soundtrack (see services/soundtrack.js) needs lazy-loading.
|
|
||||||
chinesecheckers: [(scene) => musicFrom(scene, 'chinese-music')],
|
|
||||||
// Go (Unkai-ji) is all procedural art too; it borrows the same soundtrack.
|
|
||||||
go: [(scene) => musicFrom(scene, 'chinese-music')],
|
|
||||||
mahjong: [
|
mahjong: [
|
||||||
...MAHJONG_TILES,
|
...MAHJONG_TILES,
|
||||||
// chinese soundtrack (see services/soundtrack.js) — lazy-loaded here so
|
// chinese soundtrack (see services/soundtrack.js) — lazy-loaded here so
|
||||||
|
|
@ -329,8 +323,6 @@ export const MANIFEST = {
|
||||||
image('bg-mahjongmatch-menu', 'assets/images/background-mahjongmatch.png'),
|
image('bg-mahjongmatch-menu', 'assets/images/background-mahjongmatch.png'),
|
||||||
// In-play backdrops — one is picked at random per game.
|
// In-play backdrops — one is picked at random per game.
|
||||||
...['01', '02', '03'].map((n) => image(`bg-mm-${n}`, `assets/images/background-mm-${n}.png`)),
|
...['01', '02', '03'].map((n) => image(`bg-mm-${n}`, `assets/images/background-mm-${n}.png`)),
|
||||||
// Looping video versions of the same three backdrops (Background: Video).
|
|
||||||
...['01', '02', '03'].map((n) => ({ type: 'video', key: `bg-mm-video-${n}`, path: `assets/videos/mahjong/mm-background-${n}.mp4` })),
|
|
||||||
// chinese soundtrack (see services/soundtrack.js) — lazy-loaded here so
|
// chinese soundtrack (see services/soundtrack.js) — lazy-loaded here so
|
||||||
// its audio only downloads once Mahjong Match is actually entered.
|
// its audio only downloads once Mahjong Match is actually entered.
|
||||||
(scene) => musicFrom(scene, 'chinese-music'),
|
(scene) => musicFrom(scene, 'chinese-music'),
|
||||||
|
|
@ -491,17 +483,6 @@ export const MANIFEST = {
|
||||||
// so its audio only downloads once Tempest is actually entered.
|
// so its audio only downloads once Tempest is actually entered.
|
||||||
(scene) => musicFrom(scene, 'arcadedark-music'),
|
(scene) => musicFrom(scene, 'arcadedark-music'),
|
||||||
],
|
],
|
||||||
defender: [
|
|
||||||
// arcadedark soundtrack (see services/soundtrack.js) — lazy-loaded here
|
|
||||||
// so its audio only downloads once Defender is actually entered.
|
|
||||||
(scene) => musicFrom(scene, 'arcadedark-music'),
|
|
||||||
],
|
|
||||||
geometrywars: [
|
|
||||||
// arcadedark soundtrack (see services/soundtrack.js) — lazy-loaded here
|
|
||||||
// so its audio only downloads once Geometry Wars is actually entered.
|
|
||||||
// Everything else in the game is drawn procedurally; no image assets.
|
|
||||||
(scene) => musicFrom(scene, 'arcadedark-music'),
|
|
||||||
],
|
|
||||||
mastermind: [
|
mastermind: [
|
||||||
// hacker soundtrack (see services/soundtrack.js) — lazy-loaded here so
|
// hacker soundtrack (see services/soundtrack.js) — lazy-loaded here so
|
||||||
// its audio only downloads once Mastermind is actually entered.
|
// its audio only downloads once Mastermind is actually entered.
|
||||||
|
|
|
||||||
|
|
@ -27,19 +27,19 @@ export function getGame(slug) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Built-in catalog so the menu has something to show.
|
// Built-in catalog so the menu has something to show.
|
||||||
registerGame({ slug: 'backgammon', name: 'Backgammon', category: 'tabletop', minPlayers: 2, maxPlayers: 2, minOpponents: 1, maxOpponents: 1, hasTutorial: true, iconFrame: 0 });
|
registerGame({ slug: 'backgammon', name: 'Backgammon', category: 'tabletop', minPlayers: 2, maxPlayers: 2, minOpponents: 1, maxOpponents: 1, hasTutorial: true, iconFrame: 0, defaultPlayfield: 'dark' });
|
||||||
registerGame({ slug: 'parchisi', name: 'Parchisi', category: 'tabletop', minPlayers: 2, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, defaultOpponents: 3, hasTutorial: true, iconFrame: 1 });
|
registerGame({ slug: 'parchisi', name: 'Parchisi', category: 'tabletop', minPlayers: 1, maxPlayers: 4, minOpponents: 3, maxOpponents: 3, hasTutorial: true, iconFrame: 1 });
|
||||||
registerGame({ slug: 'blackjack', name: 'Blackjack', category: 'casino', cardGame: true, minPlayers: 1, maxPlayers: 7, minOpponents: 0, maxOpponents: 6, iconFrame: 2 });
|
registerGame({ slug: 'blackjack', name: 'Blackjack', category: 'casino', cardGame: true, minPlayers: 1, maxPlayers: 7, minOpponents: 0, maxOpponents: 6, iconFrame: 2 });
|
||||||
registerGame({ slug: 'holdem', name: "Texas Hold 'Em", category: 'casino', cardGame: true, minPlayers: 2, maxPlayers: 8, minOpponents: 3, maxOpponents: 7, iconFrame: 3 });
|
registerGame({ slug: 'holdem', name: "Texas Hold 'Em", category: 'casino', cardGame: true, minPlayers: 2, maxPlayers: 8, minOpponents: 3, maxOpponents: 7, iconFrame: 3 });
|
||||||
registerGame({ slug: 'yatzi', name: 'Yahtzee', category: 'cards', minPlayers: 1, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, hasTutorial: true, iconFrame: 4 });
|
registerGame({ slug: 'yatzi', name: 'Zahtzee', category: 'cards', minPlayers: 1, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, iconFrame: 4 });
|
||||||
registerGame({ slug: 'skipbo', name: 'Skip-Bo', category: 'cards', cardGame: true, minPlayers: 1, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, iconFrame: 5 });
|
registerGame({ slug: 'skipbo', name: 'Skip-Bo', category: 'cards', cardGame: true, minPlayers: 1, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, iconFrame: 5 });
|
||||||
registerGame({ slug: 'phase10', name: 'Phase 10', category: 'cards', cardGame: true, minPlayers: 1, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, iconFrame: 6 });
|
registerGame({ slug: 'phase10', name: 'Phase 10', category: 'cards', cardGame: true, minPlayers: 1, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, iconFrame: 6 });
|
||||||
registerGame({ slug: 'chinesecheckers', name: 'Chinese Checkers', category: 'tabletop', minPlayers: 2, maxPlayers: 6, minOpponents: 1, maxOpponents: 5, defaultOpponents: 5, hasTutorial: true, iconFrame: 7 });
|
registerGame({ slug: 'chinesecheckers', name: 'Chinese Checkers', category: 'tabletop', minPlayers: 6, maxPlayers: 6, minOpponents: 5, maxOpponents: 5, hasTutorial: true, iconFrame: 7 });
|
||||||
registerGame({ slug: 'gofish', name: 'Go Fish', category: 'cards', cardGame: true, minPlayers: 1, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, iconFrame: 8 });
|
registerGame({ slug: 'gofish', name: 'Go Fish', category: 'cards', cardGame: true, minPlayers: 1, maxPlayers: 4, minOpponents: 3, maxOpponents: 3, iconFrame: 8 });
|
||||||
registerGame({ slug: 'uno', name: 'Uno', category: 'cards', cardGame: false, minPlayers: 1, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, iconFrame: 9 });
|
registerGame({ slug: 'uno', name: 'Uno', category: 'cards', cardGame: false, minPlayers: 1, maxPlayers: 4, minOpponents: 3, maxOpponents: 3, iconFrame: 9 });
|
||||||
registerGame({ slug: 'craps', name: 'Craps', category: 'casino', minPlayers: 1, maxPlayers: 7, minOpponents: 0, maxOpponents: 6, iconFrame: 10 });
|
registerGame({ slug: 'craps', name: 'Craps', category: 'casino', minPlayers: 1, maxPlayers: 7, minOpponents: 0, maxOpponents: 6, iconFrame: 10 });
|
||||||
registerGame({ slug: 'roulette', name: 'Roulette', category: 'casino', minPlayers: 1, maxPlayers: 7, minOpponents: 0, maxOpponents: 6, iconFrame: 11 });
|
registerGame({ slug: 'roulette', name: 'Roulette', category: 'casino', minPlayers: 1, maxPlayers: 7, minOpponents: 0, maxOpponents: 6, iconFrame: 11 });
|
||||||
registerGame({ slug: 'mexicantrain', name: 'Mexican Train', category: 'tabletop', minPlayers: 2, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, defaultOpponents: 3, hasTutorial: true, iconFrame: 12 });
|
registerGame({ slug: 'mexicantrain', name: 'Mexican Train', category: 'tabletop', minPlayers: 2, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, hasTutorial: true, iconFrame: 12 });
|
||||||
registerGame({ slug: 'hearts', name: 'Hearts', category: 'cards', cardGame: true, minPlayers: 4, maxPlayers: 4, minOpponents: 3, maxOpponents: 3, iconFrame: 13 });
|
registerGame({ slug: 'hearts', name: 'Hearts', category: 'cards', cardGame: true, minPlayers: 4, maxPlayers: 4, minOpponents: 3, maxOpponents: 3, iconFrame: 13 });
|
||||||
registerGame({ slug: 'catan', name: 'Settlers of Catan', category: 'tabletop', cardGame: true, minPlayers: 3, maxPlayers: 4, minOpponents: 2, maxOpponents: 3, hasTutorial: true, iconFrame: 14 });
|
registerGame({ slug: 'catan', name: 'Settlers of Catan', category: 'tabletop', cardGame: true, minPlayers: 3, maxPlayers: 4, minOpponents: 2, maxOpponents: 3, hasTutorial: true, iconFrame: 14 });
|
||||||
registerGame({ slug: 'tickettoride', name: 'Ticket to Ride', category: 'tabletop', cardGame: true, minPlayers: 2, maxPlayers: 5, minOpponents: 1, maxOpponents: 4, hasTutorial: true, iconFrame: 15 });
|
registerGame({ slug: 'tickettoride', name: 'Ticket to Ride', category: 'tabletop', cardGame: true, minPlayers: 2, maxPlayers: 5, minOpponents: 1, maxOpponents: 4, hasTutorial: true, iconFrame: 15 });
|
||||||
|
|
@ -50,19 +50,19 @@ registerGame({ slug: 'dominion', name: 'Dominion', category: 'cards', cardGame:
|
||||||
registerGame({ slug: 'checkers', name: 'Checkers', category: 'tabletop', minPlayers: 2, maxPlayers: 2, minOpponents: 1, maxOpponents: 1, iconFrame: 20, defaultPlayfield: 'cherry' });
|
registerGame({ slug: 'checkers', name: 'Checkers', category: 'tabletop', minPlayers: 2, maxPlayers: 2, minOpponents: 1, maxOpponents: 1, iconFrame: 20, defaultPlayfield: 'cherry' });
|
||||||
registerGame({ slug: 'chess', name: 'Chess', category: 'tabletop', minPlayers: 2, maxPlayers: 2, minOpponents: 1, maxOpponents: 1, iconFrame: 21, defaultPlayfield: 'dark' });
|
registerGame({ slug: 'chess', name: 'Chess', category: 'tabletop', minPlayers: 2, maxPlayers: 2, minOpponents: 1, maxOpponents: 1, iconFrame: 21, defaultPlayfield: 'dark' });
|
||||||
registerGame({ slug: 'wordle', name: 'Wordle Race', category: 'word', minPlayers: 2, maxPlayers: 2, minOpponents: 1, maxOpponents: 1, iconFrame: 22 });
|
registerGame({ slug: 'wordle', name: 'Wordle Race', category: 'word', minPlayers: 2, maxPlayers: 2, minOpponents: 1, maxOpponents: 1, iconFrame: 22 });
|
||||||
registerGame({ slug: 'scrabble', name: 'Wordsmith', category: 'word', minPlayers: 2, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, iconFrame: 23 });
|
registerGame({ slug: 'scrabble', name: 'Scrabble', category: 'word', minPlayers: 2, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, iconFrame: 23 });
|
||||||
registerGame({ slug: 'ghost', name: 'Ghost', category: 'word', minPlayers: 2, maxPlayers: 2, minOpponents: 1, maxOpponents: 1, iconFrame: 24 });
|
registerGame({ slug: 'ghost', name: 'Ghost', category: 'word', minPlayers: 2, maxPlayers: 2, minOpponents: 1, maxOpponents: 1, iconFrame: 24 });
|
||||||
registerGame({ slug: 'wordladder', name: 'Word Ladder', category: 'word', minPlayers: 1, maxPlayers: 2, minOpponents: 0, maxOpponents: 1, iconFrame: 25 });
|
registerGame({ slug: 'wordladder', name: 'Word Ladder', category: 'word', minPlayers: 1, maxPlayers: 2, minOpponents: 0, maxOpponents: 1, iconFrame: 25 });
|
||||||
registerGame({ slug: 'wordsearch', name: 'Word Search', category: 'word', minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, iconFrame: 26 });
|
registerGame({ slug: 'wordsearch', name: 'Word Search', category: 'word', minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, iconFrame: 26 });
|
||||||
registerGame({ slug: 'hangman', name: 'Hangman', category: 'word', minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, iconFrame: 27 });
|
registerGame({ slug: 'hangman', name: 'Hangman', category: 'word', minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, iconFrame: 27 });
|
||||||
registerGame({ slug: 'sudoku', name: 'Sudoku', category: 'word', minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, iconFrame: 28 });
|
registerGame({ slug: 'sudoku', name: 'Sudoku', category: 'word', minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, iconFrame: 28 });
|
||||||
registerGame({ slug: 'othello', name: 'Othello', category: 'tabletop', minPlayers: 2, maxPlayers: 2, minOpponents: 1, maxOpponents: 1, hasTutorial: true, iconFrame: 29 });
|
registerGame({ slug: 'othello', name: 'Othello', category: 'tabletop', minPlayers: 2, maxPlayers: 2, minOpponents: 1, maxOpponents: 1, iconFrame: 29, defaultPlayfield: 'cherry' });
|
||||||
registerGame({ slug: 'go', name: 'Go', category: 'tabletop', minPlayers: 2, maxPlayers: 2, minOpponents: 1, maxOpponents: 1, iconFrame: 30, defaultPlayfield: 'dark', hasTutorial: true });
|
registerGame({ slug: 'go', name: 'Go', category: 'tabletop', minPlayers: 2, maxPlayers: 2, minOpponents: 1, maxOpponents: 1, iconFrame: 30, defaultPlayfield: 'dark' });
|
||||||
registerGame({ slug: 'battleship', name: 'Battleship', category: 'tabletop', minPlayers: 2, maxPlayers: 2, minOpponents: 1, maxOpponents: 1, hasTutorial: true, iconFrame: 31 });
|
registerGame({ slug: 'battleship', name: 'Battleship', category: 'tabletop', minPlayers: 2, maxPlayers: 2, minOpponents: 1, maxOpponents: 1, hasTutorial: true, iconFrame: 31 });
|
||||||
registerGame({ slug: 'mastermind', name: 'Mastermind', category: 'tabletop', minPlayers: 2, maxPlayers: 2, minOpponents: 1, maxOpponents: 1, hasTutorial: true, iconFrame: 32 });
|
registerGame({ slug: 'mastermind', name: 'Mastermind', category: 'tabletop', minPlayers: 2, maxPlayers: 2, minOpponents: 1, maxOpponents: 1, hasTutorial: true, iconFrame: 32 });
|
||||||
registerGame({ slug: 'connect4', name: 'Connect 4', category: 'tabletop', minPlayers: 2, maxPlayers: 2, minOpponents: 1, maxOpponents: 1, iconFrame: 33 });
|
registerGame({ slug: 'connect4', name: 'Connect 4', category: 'tabletop', minPlayers: 2, maxPlayers: 2, minOpponents: 1, maxOpponents: 1, iconFrame: 33 });
|
||||||
registerGame({ slug: 'boggle', name: 'Boggle', category: 'word', minPlayers: 1, maxPlayers: 4, minOpponents: 0, maxOpponents: 3, hasTutorial: true, iconFrame: 34 });
|
registerGame({ slug: 'boggle', name: 'Boggle', category: 'word', minPlayers: 2, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, iconFrame: 34 });
|
||||||
registerGame({ slug: 'oldmaid', name: 'Old Maid', category: 'cards', cardGame: true, minPlayers: 1, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, iconFrame: 35 });
|
registerGame({ slug: 'oldmaid', name: 'Old Maid', category: 'cards', cardGame: true, minPlayers: 1, maxPlayers: 4, minOpponents: 3, maxOpponents: 3, iconFrame: 35 });
|
||||||
registerGame({ slug: 'blokus', name: 'Blokus', category: 'tabletop', minPlayers: 2, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, hasTutorial: true, iconFrame: 36 });
|
registerGame({ slug: 'blokus', name: 'Blokus', category: 'tabletop', minPlayers: 2, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, hasTutorial: true, iconFrame: 36 });
|
||||||
registerGame({ slug: 'spellingbee', name: 'Spelling Bee', category: 'word', minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, iconFrame: 37 });
|
registerGame({ slug: 'spellingbee', name: 'Spelling Bee', category: 'word', minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, iconFrame: 37 });
|
||||||
registerGame({ slug: 'minicrossword', name: 'Mini Crossword', category: 'word', minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, iconFrame: 38 });
|
registerGame({ slug: 'minicrossword', name: 'Mini Crossword', category: 'word', minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, iconFrame: 38 });
|
||||||
|
|
@ -73,9 +73,9 @@ registerGame({ slug: 'splendor', name: 'Splendor', category: 'cards', cardGame:
|
||||||
registerGame({ slug: 'labyrinth', name: 'Labyrinth', category: 'tabletop', minPlayers: 2, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, hasTutorial: true, iconFrame: 43, defaultPlayfield: 'fantasy' });
|
registerGame({ slug: 'labyrinth', name: 'Labyrinth', category: 'tabletop', minPlayers: 2, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, hasTutorial: true, iconFrame: 43, defaultPlayfield: 'fantasy' });
|
||||||
registerGame({ slug: 'videopoker', name: 'Video Poker', category: 'casino', cardGame: true, minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, iconFrame: 44 });
|
registerGame({ slug: 'videopoker', name: 'Video Poker', category: 'casino', cardGame: true, minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, iconFrame: 44 });
|
||||||
registerGame({ slug: 'farkel', name: 'Farkle', category: 'cards', minPlayers: 2, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, hasTutorial: true, iconFrame: 45 });
|
registerGame({ slug: 'farkel', name: 'Farkle', category: 'cards', minPlayers: 2, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, hasTutorial: true, iconFrame: 45 });
|
||||||
registerGame({ slug: 'stratego', name: 'Stratego', category: 'tabletop', minPlayers: 2, maxPlayers: 2, minOpponents: 1, maxOpponents: 1, hasTutorial: true, iconFrame: 46 });
|
registerGame({ slug: 'stratego', name: 'Stratego', category: 'tabletop', minPlayers: 2, maxPlayers: 2, minOpponents: 1, maxOpponents: 1, hasTutorial: false, iconFrame: 46, defaultPlayfield: 'combat' });
|
||||||
registerGame({ slug: 'kiitos', name: 'Kiitos', category: 'word', minPlayers: 2, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, iconFrame: 47 });
|
registerGame({ slug: 'kiitos', name: 'Kiitos', category: 'word', minPlayers: 2, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, iconFrame: 47 });
|
||||||
registerGame({ slug: 'monopoly', name: 'Monopoly', category: 'tabletop', minPlayers: 2, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, defaultOpponents: 3, hasTutorial: true, iconFrame: 48 });
|
registerGame({ slug: 'monopoly', name: 'Monopoly', category: 'tabletop', minPlayers: 2, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, iconFrame: 48, defaultPlayfield: 'cherry' });
|
||||||
registerGame({ slug: 'triominoes', name: 'Tri-Ominoes', category: 'word', minPlayers: 2, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, iconFrame: 49 });
|
registerGame({ slug: 'triominoes', name: 'Tri-Ominoes', category: 'word', minPlayers: 2, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, iconFrame: 49 });
|
||||||
registerGame({ slug: 'freecell', name: 'Freecell', category: 'cards', cardGame: true, minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, iconFrame: 50 });
|
registerGame({ slug: 'freecell', name: 'Freecell', category: 'cards', cardGame: true, minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, iconFrame: 50 });
|
||||||
registerGame({ slug: 'rushhour', name: 'Rush Hour', category: 'logic', minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, hasTutorial: true, iconFrame: 51 });
|
registerGame({ slug: 'rushhour', name: 'Rush Hour', category: 'logic', minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, hasTutorial: true, iconFrame: 51 });
|
||||||
|
|
@ -95,7 +95,7 @@ registerGame({ slug: 'canasta', name: 'Canasta', category: 'cards', cardGame: tr
|
||||||
registerGame({ slug: 'dotlink', name: 'Dot Link', category: 'logic', minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, iconFrame: 66 });
|
registerGame({ slug: 'dotlink', name: 'Dot Link', category: 'logic', minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, iconFrame: 66 });
|
||||||
registerGame({ slug: '2048', name: '2048', category: 'logic', minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, iconFrame: 67 });
|
registerGame({ slug: '2048', name: '2048', category: 'logic', minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, iconFrame: 67 });
|
||||||
registerGame({ slug: 'rummikub', name: 'Rummikub', category: 'cards', cardGame: true, minPlayers: 2, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, hasTutorial: true, iconFrame: 68 });
|
registerGame({ slug: 'rummikub', name: 'Rummikub', category: 'cards', cardGame: true, minPlayers: 2, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, hasTutorial: true, iconFrame: 68 });
|
||||||
registerGame({ slug: 'ginrummy', name: 'Gin Rummy', category: 'cards', cardGame: true, minPlayers: 2, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, hasTutorial: true, iconFrame: 69 });
|
registerGame({ slug: 'ginrummy', name: 'Gin Rummy', category: 'cards', cardGame: true, minPlayers: 2, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, hasTutorial: false, iconFrame: 69 });
|
||||||
registerGame({ slug: 'risk', name: 'Risk', category: 'tabletop', minPlayers: 2, maxPlayers: 6, minOpponents: 1, maxOpponents: 5, defaultOpponents: 3, hasTutorial: true, iconFrame: 54, defaultPlayfield: 'combat' });
|
registerGame({ slug: 'risk', name: 'Risk', category: 'tabletop', minPlayers: 2, maxPlayers: 6, minOpponents: 1, maxOpponents: 5, defaultOpponents: 3, hasTutorial: true, iconFrame: 54, defaultPlayfield: 'combat' });
|
||||||
registerGame({ slug: 'geniussquare', name: 'Genius Square', category: 'logic', minPlayers: 1, maxPlayers: 2, minOpponents: 1, maxOpponents: 1, iconFrame: 70 });
|
registerGame({ slug: 'geniussquare', name: 'Genius Square', category: 'logic', minPlayers: 1, maxPlayers: 2, minOpponents: 1, maxOpponents: 1, iconFrame: 70 });
|
||||||
registerGame({ slug: 'katamino', name: 'Katamino', category: 'logic', minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, iconFrame: 71 });
|
registerGame({ slug: 'katamino', name: 'Katamino', category: 'logic', minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, iconFrame: 71 });
|
||||||
|
|
@ -124,5 +124,3 @@ registerGame({ slug: 'wolfenstein', name: 'Wolfenstein 3D', category: 'arcade-co
|
||||||
registerGame({ slug: 'pipepuzzle', name: 'Pipe Puzzle', category: 'logic', minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, hasTutorial: true, iconFrame: 94 });
|
registerGame({ slug: 'pipepuzzle', name: 'Pipe Puzzle', category: 'logic', minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, hasTutorial: true, iconFrame: 94 });
|
||||||
registerGame({ slug: 'tents', name: 'Tents & Trees', category: 'logic', minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, iconFrame: 95 });
|
registerGame({ slug: 'tents', name: 'Tents & Trees', category: 'logic', minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, iconFrame: 95 });
|
||||||
registerGame({ slug: 'jigsaw', name: 'Jigsaw', category: 'logic', minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, iconFrame: 96 });
|
registerGame({ slug: 'jigsaw', name: 'Jigsaw', category: 'logic', minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, iconFrame: 96 });
|
||||||
registerGame({ slug: 'defender', name: 'Defender', category: 'arcade-console-pc', minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, iconFrame: 97 });
|
|
||||||
registerGame({ slug: 'geometrywars', name: 'Geometry Wars', category: 'arcade-console-pc', minPlayers: 1, maxPlayers: 1, minOpponents: 0, maxOpponents: 0, iconFrame: 98 });
|
|
||||||
|
|
|
||||||
|
|
@ -1,37 +1,22 @@
|
||||||
// Azul AI — synchronous, in-browser heuristic with a real skill ladder.
|
// Azul AI — synchronous, in-browser heuristic. 1-ply greedy over a board
|
||||||
//
|
// evaluation, with a skill model (1–5) that adds blunders / score noise and
|
||||||
// The core is a fast incremental valuation of "player P takes N tiles of colour
|
// picks from a widening top-N, exactly the shape used by SplendorAI.
|
||||||
// C onto line L" (no state cloning), built from:
|
|
||||||
// • wall points the line will score when it tiles (adjacency), plus progress
|
|
||||||
// toward the +7 column / +10 colour sets, discounted by how soon the game
|
|
||||||
// will end
|
|
||||||
// • partial lines valued by their chance to complete (they carry over rounds,
|
|
||||||
// but are worthless if the game ends first)
|
|
||||||
// • floor-line penalty change, and the first-player marker's worth
|
|
||||||
// • end-timing: completing a wall row ends the game — good when ahead,
|
|
||||||
// bad when behind
|
|
||||||
// Higher skills add denial — how good the table is for the next player(s) after
|
|
||||||
// this take, which also produces natural hate-drafting — and skill 5 checks its
|
|
||||||
// best few candidates with a greedy rollout to the end of the round.
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
COLORS, WALL_SIZE, FLOOR_PENALTIES, FLOOR_SIZE,
|
COLORS, WALL_SIZE, FLOOR_PENALTIES, FLOOR_SIZE,
|
||||||
lineCapacity, ROW_BONUS, COLUMN_BONUS, COLOR_BONUS,
|
lineCapacity, wallColumnFor, ROW_BONUS, COLUMN_BONUS, COLOR_BONUS,
|
||||||
} from './AzulData.js';
|
} from './AzulData.js';
|
||||||
import {
|
import { legalMoves, applyMove, scorePlacement } from './AzulLogic.js';
|
||||||
legalMoves, applyMove, resolveRound, scorePlacement, wallOptions, cellColor,
|
|
||||||
isFreeWall, bonusStatus, defaultWallColumn,
|
|
||||||
} from './AzulLogic.js';
|
|
||||||
|
|
||||||
const SKILL_PROFILES = {
|
const SKILL_PROFILES = {
|
||||||
1: { topN: 2, blunder: 0.20, noise: 2.2, denial: 0, others: 0, plan: 1, rollout: 0, delay: [700, 1200] },
|
1: { topN: 5, blunder: 0.45, noise: 14, delay: [700, 1200] },
|
||||||
2: { topN: 1, blunder: 0.10, noise: 1.8, denial: 0.15, others: 0, plan: 1, rollout: 0, delay: [650, 1100] },
|
2: { topN: 4, blunder: 0.25, noise: 9, delay: [650, 1100] },
|
||||||
3: { topN: 1, blunder: 0.06, noise: 1.2, denial: 0.3, others: 0.1, plan: 1, rollout: 0, delay: [600, 1000] },
|
3: { topN: 3, blunder: 0.12, noise: 5, delay: [600, 1000] },
|
||||||
4: { topN: 1, blunder: 0.01, noise: 0.3, denial: 0.6, others: 0.2, plan: 1, rollout: 0, delay: [520, 900] },
|
4: { topN: 2, blunder: 0.04, noise: 2, delay: [520, 900] },
|
||||||
5: { topN: 1, blunder: 0, noise: 0, denial: 0.75, others: 0.25, plan: 1, rollout: 6, delay: [440, 820] },
|
5: { topN: 1, blunder: 0.00, noise: 0, delay: [440, 820] },
|
||||||
};
|
};
|
||||||
|
|
||||||
export function profileFor(skill) {
|
function profileFor(skill) {
|
||||||
return SKILL_PROFILES[Math.max(1, Math.min(5, skill | 0))] ?? SKILL_PROFILES[3];
|
return SKILL_PROFILES[Math.max(1, Math.min(5, skill | 0))] ?? SKILL_PROFILES[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,353 +25,73 @@ export function nextThinkDelay(skill) {
|
||||||
return lo + Math.random() * (hi - lo);
|
return lo + Math.random() * (hi - lo);
|
||||||
}
|
}
|
||||||
|
|
||||||
const FLOOR_CUM = [0];
|
// Static evaluation of a player's board (higher = better). Captures realised
|
||||||
for (let k = 0; k < FLOOR_SIZE; k++) FLOOR_CUM.push(FLOOR_CUM[k] + FLOOR_PENALTIES[k]);
|
// score plus the *potential* locked up in pattern lines, minus floor liability,
|
||||||
const floorPen = (len) => FLOOR_CUM[Math.min(FLOOR_SIZE, Math.max(0, len))];
|
// plus a nudge toward the lucrative end-game row/column/colour bonuses.
|
||||||
|
function evalPlayer(state, seat) {
|
||||||
|
const p = state.players[seat];
|
||||||
|
let v = p.score * 10;
|
||||||
|
|
||||||
// Tunable weights (measured with tools/verifyAzul.js's ladder).
|
// Pattern lines: reward progress, and reward a line that is exactly full
|
||||||
export const TUNE = {
|
// (it will tile and score next phase) by the points it would earn.
|
||||||
needCost: 0.6, // per tile a partial line still needs
|
|
||||||
probBase: 0.92, probSlope: 0.13,
|
|
||||||
exposure: 1.5, // colours left on the table that no line of ours can take
|
|
||||||
floorMul: 1.3, // floor-penalty weight
|
|
||||||
endLead: 2, endTrail: -8,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Set-bonus potential by how many of the five are in place.
|
|
||||||
const POTENTIAL = [0, 0.03, 0.09, 0.2, 0.45, 1];
|
|
||||||
|
|
||||||
// ── game context ─────────────────────────────────────────────────────────────
|
|
||||||
// How close the game is to ending, and who is ahead (projected).
|
|
||||||
export function gameContext(state, seat) {
|
|
||||||
const free = isFreeWall(state);
|
|
||||||
let maxRow = 0, endsThisRound = false;
|
|
||||||
for (const p of state.players) {
|
|
||||||
for (let r = 0; r < WALL_SIZE; r++) {
|
|
||||||
const n = p.wall[r].filter(Boolean).length;
|
|
||||||
maxRow = Math.max(maxRow, n);
|
|
||||||
if (n === WALL_SIZE - 1) {
|
|
||||||
const l = p.lines[r];
|
|
||||||
if (l.color && l.count === lineCapacity(r) && wallOptions(p, r, l.color, free).length) endsThisRound = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const future = endsThisRound ? 0 : maxRow >= 4 ? 0.4 : maxRow === 3 ? 0.75 : 1;
|
|
||||||
const proj = state.players.map((p) => p.score + bonusStatus(p).locked + pendingPoints(p, free) + floorPen(p.floor.length));
|
|
||||||
const mine = proj[seat];
|
|
||||||
let best = -Infinity;
|
|
||||||
proj.forEach((v, i) => { if (i !== seat) best = Math.max(best, v); });
|
|
||||||
return { free, future, endsThisRound, lead: mine - best, proj, players: state.playerCount };
|
|
||||||
}
|
|
||||||
|
|
||||||
// Points the already-full pattern lines will score this round (top to bottom).
|
|
||||||
function pendingPoints(p, free) {
|
|
||||||
const placed = [];
|
|
||||||
let pts = 0;
|
|
||||||
for (let r = 0; r < WALL_SIZE; r++) {
|
|
||||||
const l = p.lines[r];
|
|
||||||
if (!l.color || l.count !== lineCapacity(r)) continue;
|
|
||||||
const opts = wallOptions(p, r, l.color, free);
|
|
||||||
if (!opts.length) continue;
|
|
||||||
const c = free ? defaultWallColumn(p, r, l.color, opts) : opts[0];
|
|
||||||
p.wall[r][c] = true;
|
|
||||||
pts += scorePlacement(p.wall, r, c);
|
|
||||||
placed.push([r, c]);
|
|
||||||
}
|
|
||||||
for (const [r, c] of placed) p.wall[r][c] = false;
|
|
||||||
return pts;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── valuation ────────────────────────────────────────────────────────────────
|
|
||||||
// Value of eventually setting `color` on wall row `row` (wall cell chosen as the
|
|
||||||
// free-wall default). Returns { v, col } or null when it has nowhere to go.
|
|
||||||
function placeValue(p, row, color, ctx, plan) {
|
|
||||||
const opts = wallOptions(p, row, color, ctx.free);
|
|
||||||
if (!opts.length) return null;
|
|
||||||
const col = ctx.free ? defaultWallColumn(p, row, color, opts) : opts[0];
|
|
||||||
p.wall[row][col] = true;
|
|
||||||
const pts = scorePlacement(p.wall, row, col);
|
|
||||||
p.wall[row][col] = false;
|
|
||||||
|
|
||||||
let colN = 0, colorN = 0, rowN = 0;
|
|
||||||
for (let r = 0; r < WALL_SIZE; r++) if (p.wall[r][col]) colN++;
|
|
||||||
for (let c = 0; c < WALL_SIZE; c++) if (p.wall[row][c]) rowN++;
|
|
||||||
for (let r = 0; r < WALL_SIZE; r++) for (let c = 0; c < WALL_SIZE; c++) if (cellColor(p, r, c) === color) colorN++;
|
|
||||||
|
|
||||||
const f = ctx.future;
|
|
||||||
const gain = (n, bonus) => {
|
|
||||||
const after = n + 1;
|
|
||||||
const a = after === WALL_SIZE ? bonus : bonus * POTENTIAL[after] * f;
|
|
||||||
const b = n === WALL_SIZE ? bonus : bonus * POTENTIAL[n] * f;
|
|
||||||
return a - b;
|
|
||||||
};
|
|
||||||
let v = pts;
|
|
||||||
v += plan * (gain(colN, COLUMN_BONUS) + gain(colorN, COLOR_BONUS) + gain(rowN, ROW_BONUS) * 0.5);
|
|
||||||
// Central cells connect in more directions — a small early-game preference.
|
|
||||||
v += plan * f * (2 - Math.abs(col - 2)) * 0.15;
|
|
||||||
// End-timing: completing a row ends the game after this round.
|
|
||||||
if (rowN + 1 === WALL_SIZE) v += plan * (ctx.lead >= 0 ? TUNE.endLead + Math.min(6, ctx.lead * 0.3) : TUNE.endTrail + ctx.lead * 0.4);
|
|
||||||
return { v, col };
|
|
||||||
}
|
|
||||||
|
|
||||||
// Value of a pattern line holding `count` of `color` (count may be 0).
|
|
||||||
function lineValue(p, row, color, count, ctx, plan) {
|
|
||||||
if (!color || count === 0) return 0;
|
|
||||||
const cap = lineCapacity(row);
|
|
||||||
const pv = placeValue(p, row, color, ctx, plan);
|
|
||||||
if (!pv) return -count; // free wall: would be dumped
|
|
||||||
if (count >= cap) return pv.v;
|
|
||||||
const need = cap - count;
|
|
||||||
// Partial lines carry over — but only matter if the game continues.
|
|
||||||
const carry = ctx.endsThisRound ? 0 : ctx.future;
|
|
||||||
const prob = Math.max(0.15, TUNE.probBase - TUNE.probSlope * need) * (0.35 + 0.65 * carry);
|
|
||||||
return pv.v * prob - TUNE.needCost * need * plan;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gain for player `p` taking `n` tiles of `color` onto `line` (index or
|
|
||||||
// 'floor'), optionally with the first-player marker. No mutation.
|
|
||||||
function takeGain(p, color, n, line, takesFirst, ctx, plan) {
|
|
||||||
let placed = 0, v = 0;
|
|
||||||
if (line !== 'floor') {
|
|
||||||
const l = p.lines[line];
|
|
||||||
const cap = lineCapacity(line);
|
|
||||||
placed = Math.min(cap - l.count, n);
|
|
||||||
v += lineValue(p, line, color, l.count + placed, ctx, plan) - lineValue(p, line, l.color, l.count, ctx, plan);
|
|
||||||
}
|
|
||||||
const add = n - placed + (takesFirst ? 1 : 0);
|
|
||||||
v += TUNE.floorMul * (floorPen(p.floor.length + add) - floorPen(p.floor.length));
|
|
||||||
if (takesFirst) v += ctx.endsThisRound ? 0 : (1 + 0.3 * (ctx.players - 2)) * ctx.future * plan;
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Colour counts per source: [{ counts, type, index }]
|
|
||||||
function sourceCounts(state) {
|
|
||||||
const out = state.factories.map((f, index) => {
|
|
||||||
const counts = {}; for (const t of f) counts[t] = (counts[t] ?? 0) + 1;
|
|
||||||
return { type: 'factory', index, counts };
|
|
||||||
});
|
|
||||||
const counts = {}; for (const t of state.center) counts[t] = (counts[t] ?? 0) + 1;
|
|
||||||
out.push({ type: 'center', counts, first: state.centerHasFirst });
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The best gain a player could get from a table of sources.
|
|
||||||
function bestGain(p, sources, ctx, plan) {
|
|
||||||
let best = -Infinity;
|
|
||||||
for (const s of sources) {
|
|
||||||
for (const color of COLORS) {
|
|
||||||
const n = s.counts[color];
|
|
||||||
if (!n) continue;
|
|
||||||
const tf = s.type === 'center' && s.first;
|
|
||||||
for (let i = 0; i < WALL_SIZE; i++) {
|
for (let i = 0; i < WALL_SIZE; i++) {
|
||||||
const l = p.lines[i];
|
const line = p.lines[i];
|
||||||
if (l.count >= lineCapacity(i) || (l.color && l.color !== color)) continue;
|
if (line.color === null) continue;
|
||||||
if (!wallOptions(p, i, color, ctx.free).length) continue;
|
const cap = lineCapacity(i);
|
||||||
const g = takeGain(p, color, n, i, tf, ctx, plan);
|
if (line.count === cap) {
|
||||||
if (g > best) best = g;
|
const col = wallColumnFor(i, line.color);
|
||||||
}
|
const wall = p.wall.map((r) => r.slice());
|
||||||
const g = takeGain(p, color, n, 'floor', tf, ctx, plan);
|
wall[i][col] = true;
|
||||||
if (g > best) best = g;
|
v += scorePlacement(wall, i, col) * 8;
|
||||||
}
|
|
||||||
}
|
|
||||||
return best === -Infinity ? 0 : best;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The table after taking `color` from source `si` (leftovers to the centre).
|
|
||||||
function tableAfter(sources, si, color) {
|
|
||||||
const src = sources[si];
|
|
||||||
const out = sources.map((s) => ({ ...s, counts: { ...s.counts } }));
|
|
||||||
const center = out[out.length - 1];
|
|
||||||
if (src.type === 'factory') {
|
|
||||||
for (const c of COLORS) if (c !== color && src.counts[c]) center.counts[c] = (center.counts[c] ?? 0) + src.counts[c];
|
|
||||||
out[si].counts = {};
|
|
||||||
} else {
|
} else {
|
||||||
center.counts[color] = 0;
|
// Partial: value tiles already banked, scaled by how close to full it is.
|
||||||
center.first = false;
|
v += line.count * 2 + (line.count / cap) * 3;
|
||||||
}
|
}
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Score every legal move for the current player.
|
// Floor liability: the penalties these tiles will cost.
|
||||||
export function rankMoves(state, skill = 3) {
|
let penalty = 0;
|
||||||
const prof = profileFor(skill);
|
for (let k = 0; k < p.floor.length && k < FLOOR_SIZE; k++) penalty += FLOOR_PENALTIES[k];
|
||||||
const seat = state.current;
|
v += penalty * 4;
|
||||||
const p = state.players[seat];
|
|
||||||
const ctx = gameContext(state, seat);
|
|
||||||
const legal = legalMoves(state);
|
|
||||||
const sources = sourceCounts(state);
|
|
||||||
const n = state.playerCount;
|
|
||||||
const nextSeat = (seat + 1) % n;
|
|
||||||
const denialCache = new Map();
|
|
||||||
const ctxBySeat = state.players.map((q) => (q.seat === seat ? ctx : (prof.denial ? gameContext(state, q.seat) : null)));
|
|
||||||
const denial = (si, color) => {
|
|
||||||
if (!prof.denial) return 0;
|
|
||||||
const key = `${si}:${color}`;
|
|
||||||
if (denialCache.has(key)) return denialCache.get(key);
|
|
||||||
const after = tableAfter(sources, si, color);
|
|
||||||
let d = 0;
|
|
||||||
for (let k = 1; k < n; k++) {
|
|
||||||
const q = state.players[(seat + k) % n];
|
|
||||||
const qctx = ctxBySeat[q.seat];
|
|
||||||
const w = (q.seat === nextSeat) ? prof.denial : prof.others;
|
|
||||||
if (w) d += w * bestGain(q, after, qctx, 1);
|
|
||||||
}
|
|
||||||
denialCache.set(key, d);
|
|
||||||
return d;
|
|
||||||
};
|
|
||||||
const sourceIndex = (src) => (src.type === 'center' ? sources.length - 1 : src.index);
|
|
||||||
|
|
||||||
// Exposure: after this take, which colours left on the table have no line of
|
// Permanent wall tiles, and proximity to the end-game bonuses.
|
||||||
// ours that could take them? Those are the tiles we may be forced to floor.
|
let wallTiles = 0;
|
||||||
const expCache = new Map();
|
for (let row = 0; row < WALL_SIZE; row++) for (let col = 0; col < WALL_SIZE; col++) if (p.wall[row][col]) wallTiles++;
|
||||||
const exposure = (si, move) => {
|
v += wallTiles;
|
||||||
if (!TUNE.exposure || !prof.plan) return 0;
|
for (let row = 0; row < WALL_SIZE; row++) {
|
||||||
const key = `${si}:${move.color}:${move.line}`;
|
const n = p.wall[row].filter(Boolean).length;
|
||||||
if (expCache.has(key)) return expCache.get(key);
|
if (n === WALL_SIZE) v += ROW_BONUS; else if (n === WALL_SIZE - 1) v += 3;
|
||||||
const after = tableAfter(sources, si, move.color);
|
}
|
||||||
const remain = {};
|
for (let col = 0; col < WALL_SIZE; col++) {
|
||||||
for (const src of after) for (const c of COLORS) if (src.counts[c]) remain[c] = (remain[c] ?? 0) + src.counts[c];
|
let n = 0; for (let row = 0; row < WALL_SIZE; row++) if (p.wall[row][col]) n++;
|
||||||
let e = 0;
|
if (n === WALL_SIZE) v += COLUMN_BONUS; else if (n === WALL_SIZE - 1) v += 4;
|
||||||
|
}
|
||||||
for (const c of COLORS) {
|
for (const c of COLORS) {
|
||||||
const R = remain[c];
|
let n = 0; for (let row = 0; row < WALL_SIZE; row++) if (p.wall[row][wallColumnFor(row, c)]) n++;
|
||||||
if (!R) continue;
|
if (n === WALL_SIZE) v += COLOR_BONUS; else if (n === WALL_SIZE - 1) v += 5;
|
||||||
let home = false;
|
|
||||||
for (let i = 0; i < WALL_SIZE && !home; i++) {
|
|
||||||
const l = p.lines[i];
|
|
||||||
let color = l.color, count = l.count;
|
|
||||||
if (move.line === i) { color = move.color; count = Math.min(lineCapacity(i), l.count + sources[si].counts[move.color]); }
|
|
||||||
if (count >= lineCapacity(i) || (color && color !== c)) continue;
|
|
||||||
if (wallOptions(p, i, c, ctx.free).length) home = true;
|
|
||||||
}
|
}
|
||||||
if (!home) e += Math.min(R, 4);
|
|
||||||
}
|
|
||||||
const v = TUNE.exposure * prof.plan * e / n;
|
|
||||||
expCache.set(key, v);
|
|
||||||
return v;
|
return v;
|
||||||
};
|
|
||||||
|
|
||||||
return legal.map((move) => {
|
|
||||||
const si = sourceIndex(move.source);
|
|
||||||
const s = sources[si];
|
|
||||||
const cnt = s.counts[move.color];
|
|
||||||
const tf = s.type === 'center' && s.first;
|
|
||||||
const gain = takeGain(p, move.color, cnt, move.line, tf, ctx, prof.plan);
|
|
||||||
const score = gain - denial(si, move.color) - exposure(si, move);
|
|
||||||
return { move, score, gain };
|
|
||||||
}).sort((a, b) => b.score - a.score);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Greedy policy used inside rollouts (fast, no denial).
|
|
||||||
function greedyMove(state) {
|
|
||||||
const seat = state.current;
|
|
||||||
const p = state.players[seat];
|
|
||||||
const ctx = gameContext(state, seat);
|
|
||||||
const sources = sourceCounts(state);
|
|
||||||
let best = null, bestV = -Infinity;
|
|
||||||
for (const move of legalMoves(state)) {
|
|
||||||
const s = sources[move.source.type === 'center' ? sources.length - 1 : move.source.index];
|
|
||||||
const v = takeGain(p, move.color, s.counts[move.color], move.line, s.type === 'center' && s.first, ctx, 1);
|
|
||||||
if (v > bestV) { bestV = v; best = move; }
|
|
||||||
}
|
|
||||||
return best;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Play the rest of the round greedily, tile it, and judge the result for `seat`.
|
|
||||||
function rolloutValue(state, seat) {
|
|
||||||
let s = state;
|
|
||||||
let guard = 0;
|
|
||||||
while (s.phase === 'offer' && guard++ < 200) {
|
|
||||||
const m = greedyMove(s);
|
|
||||||
if (!m) break;
|
|
||||||
s = applyMove(s, m);
|
|
||||||
}
|
|
||||||
if (s.phase === 'scoring') s = resolveRound(s);
|
|
||||||
const free = isFreeWall(s);
|
|
||||||
const val = (p) => {
|
|
||||||
const ctx = gameContext(s, p.seat);
|
|
||||||
let v = p.score + (s.phase === 'gameOver' ? 0 : bonusStatus(p).locked * 0.6);
|
|
||||||
if (s.phase !== 'gameOver') {
|
|
||||||
for (let r = 0; r < WALL_SIZE; r++) {
|
|
||||||
const l = p.lines[r];
|
|
||||||
if (l.color && l.count) v += lineValue(p, r, l.color, l.count, ctx, 1) * 0.8;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void free;
|
|
||||||
return v;
|
|
||||||
};
|
|
||||||
const mine = val(s.players[seat]);
|
|
||||||
let opp = 0;
|
|
||||||
for (const p of s.players) if (p.seat !== seat) opp = Math.max(opp, val(p));
|
|
||||||
return mine - 0.5 * opp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a single move object for the current player, or null if none exist.
|
// Returns a single move object for the current player, or null if none exist.
|
||||||
export function chooseMove(state, skill) {
|
export function chooseMove(state, skill) {
|
||||||
const prof = profileFor(skill);
|
const prof = profileFor(skill);
|
||||||
|
const seat = state.current;
|
||||||
const legal = legalMoves(state);
|
const legal = legalMoves(state);
|
||||||
if (legal.length === 0) return null;
|
if (legal.length === 0) return null;
|
||||||
if (legal.length === 1) return legal[0];
|
if (legal.length === 1) return legal[0];
|
||||||
|
|
||||||
if (Math.random() < prof.blunder) {
|
const ranked = legal
|
||||||
// A "blunder" is a plausible-but-loose move — a line move from the top of
|
.map((move) => {
|
||||||
// the list, never a needless floor dump.
|
let score = evalPlayer(applyMove(state, move), seat);
|
||||||
const ranked = rankMoves(state, skill);
|
score += (Math.random() * 2 - 1) * prof.noise;
|
||||||
const lines = ranked.filter((r) => r.move.line !== 'floor' && r.gain > -2);
|
return { move, score };
|
||||||
const pool = (lines.length ? lines : ranked).slice(0, 6);
|
})
|
||||||
return pool[Math.floor(Math.random() * pool.length)].move;
|
|
||||||
}
|
|
||||||
|
|
||||||
let ranked = rankMoves(state, skill);
|
|
||||||
if (prof.noise) {
|
|
||||||
ranked = ranked.map((r) => ({ ...r, score: r.score + (Math.random() * 2 - 1) * prof.noise }))
|
|
||||||
.sort((a, b) => b.score - a.score);
|
.sort((a, b) => b.score - a.score);
|
||||||
}
|
|
||||||
|
|
||||||
if (prof.rollout && state.phase === 'offer') {
|
if (Math.random() < prof.blunder) {
|
||||||
const seat = state.current;
|
return legal[Math.floor(Math.random() * legal.length)];
|
||||||
const top = ranked.slice(0, prof.rollout);
|
|
||||||
let best = null, bestV = -Infinity;
|
|
||||||
for (const r of top) {
|
|
||||||
const v = rolloutValue(applyMove(state, r.move), seat) + r.score * 0.35;
|
|
||||||
if (v > bestV) { bestV = v; best = r.move; }
|
|
||||||
}
|
}
|
||||||
if (best) return best;
|
|
||||||
}
|
|
||||||
|
|
||||||
const pool = ranked.slice(0, Math.max(1, prof.topN));
|
const pool = ranked.slice(0, Math.max(1, prof.topN));
|
||||||
return pool[Math.floor(Math.random() * pool.length)].move;
|
return pool[Math.floor(Math.random() * pool.length)].move;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free wall: pick columns for this seat's completed lines, top to bottom.
|
|
||||||
// Returns { [row]: col }. Standard wall → {}.
|
|
||||||
export function chooseWallColumns(state, seat, skill = 3) {
|
|
||||||
if (!isFreeWall(state)) return {};
|
|
||||||
const p = JSON.parse(JSON.stringify(state.players[seat]));
|
|
||||||
const ctx = gameContext(state, seat);
|
|
||||||
const prof = profileFor(skill);
|
|
||||||
const out = {};
|
|
||||||
for (let r = 0; r < WALL_SIZE; r++) {
|
|
||||||
const l = p.lines[r];
|
|
||||||
if (!l.color || l.count !== lineCapacity(r)) continue;
|
|
||||||
const opts = wallOptions(p, r, l.color, true);
|
|
||||||
if (!opts.length) continue;
|
|
||||||
let best = opts[0], bestV = -Infinity;
|
|
||||||
for (const c of opts) {
|
|
||||||
p.wall[r][c] = true;
|
|
||||||
let v = scorePlacement(p.wall, r, c);
|
|
||||||
let colN = 0; for (let rr = 0; rr < WALL_SIZE; rr++) if (p.wall[rr][c]) colN++;
|
|
||||||
p.wall[r][c] = false;
|
|
||||||
v += prof.plan * COLUMN_BONUS * (colN === WALL_SIZE ? 1 : POTENTIAL[colN] * ctx.future);
|
|
||||||
// Keep later rows' options open: count colours still placeable in this column.
|
|
||||||
let open = 0;
|
|
||||||
for (let rr = r + 1; rr < WALL_SIZE; rr++) if (!p.wall[rr][c]) open++;
|
|
||||||
v += prof.plan * open * 0.05;
|
|
||||||
v += (Math.random() * 2 - 1) * prof.noise * 0.5;
|
|
||||||
if (v > bestV) { bestV = v; best = c; }
|
|
||||||
}
|
|
||||||
out[r] = best;
|
|
||||||
p.wall[r][best] = true;
|
|
||||||
p.wallColors[r][best] = l.color;
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,671 +0,0 @@
|
||||||
// AzulArt.js — procedural canvas art for the Azul tile workshop (Lisbon).
|
|
||||||
//
|
|
||||||
// Everything is baked once into Phaser canvas textures (no new image files):
|
|
||||||
// azul-room plaster wall with an azulejo wainscot + title
|
|
||||||
// cartouche, over a worn oak workbench and lamp pool
|
|
||||||
// azul-board-<big|mini>[-free][-g]
|
|
||||||
// a player board: walnut frame, cream plaster, cobalt
|
|
||||||
// header band, recessed pattern-line cells, the wall
|
|
||||||
// (faint glazed ghosts of each tile, or grey cells for
|
|
||||||
// the free wall), the floor line with its penalties;
|
|
||||||
// -g adds colour-blind glyphs to the ghosts
|
|
||||||
// azul-plate a glazed factory plate with a painted cobalt rim
|
|
||||||
// azul-tray the centre tray (wooden rim, green baize)
|
|
||||||
// azul-bag / azul-lid the cloth tile bag and the box lid (discards)
|
|
||||||
// azul-panel-<name> wood-framed cream panels for the HUD
|
|
||||||
// azul-notepad the workshop order book (log)
|
|
||||||
// azul-t-<colour>[-g] a bevelled, glazed tile with its shadow baked in
|
|
||||||
// (from the user's azul-tiles sheet when loaded)
|
|
||||||
// azul-t-first the first-player token
|
|
||||||
// azul-glow / azul-spark / azul-dust / azul-glint FX sprites
|
|
||||||
//
|
|
||||||
// Boards and panels carry a shadow margin of SHADOW px on every side: place
|
|
||||||
// them at (x - SHADOW, y - SHADOW) with origin 0.
|
|
||||||
|
|
||||||
import { canvas, rr, noisePattern } from '../../ui/casino/CasinoArt.js';
|
|
||||||
import { mulberry32 } from '../../ui/cardtable/AITiming.js';
|
|
||||||
import {
|
|
||||||
COLORS, TILE_HEX, TILE_EDGE, FLOOR_PENALTIES, FLOOR_SIZE, WALL_SIZE, wallColor, lineCapacity, tileFrame, FIRST_PLAYER_FRAME,
|
|
||||||
} from './AzulData.js';
|
|
||||||
import {
|
|
||||||
W, H, MINI, BIG, WAINSCOT, TITLE, RING, TRAY, BAG, LID, NOTEPAD, TRACKER, ACTION, SCORES,
|
|
||||||
} from './AzulLayout.js';
|
|
||||||
|
|
||||||
export const SERIF = 'Georgia, "Times New Roman", serif';
|
|
||||||
export const DISPLAY = 'Caesar, Georgia, serif';
|
|
||||||
export const SHADOW = 14;
|
|
||||||
export const TILE_TEX = { size: 112, tile: 96, ox: 7, oy: 5 }; // tile drawn at (ox, oy) in the texture
|
|
||||||
export const PLATE_TEX = 132;
|
|
||||||
export const COBALT = '#1d4f8f';
|
|
||||||
export const INK = '#3a2a16';
|
|
||||||
const hex = (n) => `#${n.toString(16).padStart(6, '0')}`;
|
|
||||||
|
|
||||||
// Colour-blind glyphs (drawn on tiles and wall ghosts when enabled).
|
|
||||||
export const GLYPH = { blue: 'circle', yellow: 'triangle', red: 'diamond', black: 'square', white: 'cross' };
|
|
||||||
|
|
||||||
function addCanvas(scene, key, c) {
|
|
||||||
if (scene.textures.exists(key)) scene.textures.remove(key);
|
|
||||||
scene.textures.addCanvas(key, c);
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── shared painters ────────────────────────────────────────────────────────────
|
|
||||||
function grain(ctx, x, y, w, h, rnd, { dark = 'rgba(50,28,10,0.16)', light = 'rgba(255,225,180,0.07)', spacing = 6, amp = 2 } = {}) {
|
|
||||||
ctx.save();
|
|
||||||
ctx.lineWidth = 1;
|
|
||||||
for (let yy = y; yy < y + h; yy += spacing * (0.6 + rnd() * 0.8)) {
|
|
||||||
ctx.strokeStyle = rnd() < 0.7 ? dark : light;
|
|
||||||
ctx.beginPath();
|
|
||||||
const ph = rnd() * 6, fq = 0.004 + rnd() * 0.01;
|
|
||||||
for (let xx = x; xx <= x + w; xx += 10) {
|
|
||||||
const yv = yy + Math.sin(xx * fq + ph) * amp + Math.sin(xx * fq * 3.1 + ph) * amp * 0.3;
|
|
||||||
if (xx === x) ctx.moveTo(xx, yv); else ctx.lineTo(xx, yv);
|
|
||||||
}
|
|
||||||
ctx.stroke();
|
|
||||||
}
|
|
||||||
ctx.restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
function wood(ctx, x, y, w, h, top, bottom, rnd, spacing = 6) {
|
|
||||||
const g = ctx.createLinearGradient(x, y, x, y + h);
|
|
||||||
g.addColorStop(0, top); g.addColorStop(1, bottom);
|
|
||||||
ctx.fillStyle = g;
|
|
||||||
ctx.fill();
|
|
||||||
ctx.save();
|
|
||||||
ctx.clip();
|
|
||||||
grain(ctx, x, y, w, h, rnd, { spacing });
|
|
||||||
ctx.fillStyle = noisePattern(ctx, 64, 20);
|
|
||||||
ctx.fillRect(x, y, w, h);
|
|
||||||
ctx.restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
function softShadow(ctx, draw, { blur = 14, dx = 0, dy = 6, color = 'rgba(0,0,0,0.45)' } = {}) {
|
|
||||||
ctx.save();
|
|
||||||
ctx.shadowColor = color;
|
|
||||||
ctx.shadowBlur = blur;
|
|
||||||
ctx.shadowOffsetX = dx;
|
|
||||||
ctx.shadowOffsetY = dy;
|
|
||||||
draw();
|
|
||||||
ctx.restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
// A recessed square (grout / inset) — darker top-left inner edge.
|
|
||||||
function inset(ctx, x, y, s, r, { fill = 'rgba(90,64,30,0.16)', dark = 'rgba(60,40,15,0.45)', light = 'rgba(255,248,230,0.7)' } = {}) {
|
|
||||||
rr(ctx, x, y, s, s, r);
|
|
||||||
ctx.fillStyle = fill;
|
|
||||||
ctx.fill();
|
|
||||||
ctx.save();
|
|
||||||
rr(ctx, x, y, s, s, r);
|
|
||||||
ctx.clip();
|
|
||||||
ctx.lineWidth = 2.5;
|
|
||||||
ctx.strokeStyle = dark;
|
|
||||||
ctx.beginPath(); ctx.moveTo(x, y + s); ctx.lineTo(x, y); ctx.lineTo(x + s, y); ctx.stroke();
|
|
||||||
ctx.strokeStyle = light;
|
|
||||||
ctx.beginPath(); ctx.moveTo(x + s, y); ctx.lineTo(x + s, y + s); ctx.lineTo(x, y + s); ctx.stroke();
|
|
||||||
ctx.restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
export function drawGlyph(ctx, kind, cx, cy, s, { fill = '#ffffff', stroke = 'rgba(0,0,0,0.75)', lw = Math.max(1.5, s * 0.14) } = {}) {
|
|
||||||
ctx.save();
|
|
||||||
ctx.beginPath();
|
|
||||||
const h = s / 2;
|
|
||||||
if (kind === 'circle') ctx.arc(cx, cy, h * 0.85, 0, Math.PI * 2);
|
|
||||||
else if (kind === 'triangle') { ctx.moveTo(cx, cy - h); ctx.lineTo(cx + h, cy + h * 0.8); ctx.lineTo(cx - h, cy + h * 0.8); ctx.closePath(); }
|
|
||||||
else if (kind === 'diamond') { ctx.moveTo(cx, cy - h); ctx.lineTo(cx + h, cy); ctx.lineTo(cx, cy + h); ctx.lineTo(cx - h, cy); ctx.closePath(); }
|
|
||||||
else if (kind === 'square') ctx.rect(cx - h * 0.78, cy - h * 0.78, h * 1.56, h * 1.56);
|
|
||||||
else if (kind === 'cross') {
|
|
||||||
const t = h * 0.36;
|
|
||||||
ctx.moveTo(cx - t, cy - h); ctx.lineTo(cx + t, cy - h); ctx.lineTo(cx + t, cy - t); ctx.lineTo(cx + h, cy - t);
|
|
||||||
ctx.lineTo(cx + h, cy + t); ctx.lineTo(cx + t, cy + t); ctx.lineTo(cx + t, cy + h); ctx.lineTo(cx - t, cy + h);
|
|
||||||
ctx.lineTo(cx - t, cy + t); ctx.lineTo(cx - h, cy + t); ctx.lineTo(cx - h, cy - t); ctx.lineTo(cx - t, cy - t); ctx.closePath();
|
|
||||||
}
|
|
||||||
ctx.lineJoin = 'round';
|
|
||||||
ctx.lineWidth = lw;
|
|
||||||
ctx.strokeStyle = stroke;
|
|
||||||
ctx.stroke();
|
|
||||||
ctx.fillStyle = fill;
|
|
||||||
ctx.fill();
|
|
||||||
ctx.restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
// The source image + frame rect of a tile in the user's sheet, or null.
|
|
||||||
function sheetFrame(scene, frameIndex) {
|
|
||||||
if (!scene.textures.exists('azul-tiles')) return null;
|
|
||||||
const tex = scene.textures.get('azul-tiles');
|
|
||||||
const fr = tex.get(frameIndex);
|
|
||||||
if (!fr || fr.name === '__BASE') return null;
|
|
||||||
return { img: tex.getSourceImage(), sx: fr.cutX, sy: fr.cutY, sw: fr.cutWidth, sh: fr.cutHeight };
|
|
||||||
}
|
|
||||||
|
|
||||||
// Procedural azulejo face (fallback when the sheet is missing).
|
|
||||||
function proceduralFace(ctx, color, x, y, s) {
|
|
||||||
const base = hex(TILE_HEX[color]);
|
|
||||||
const edge = hex(TILE_EDGE[color]);
|
|
||||||
ctx.fillStyle = base;
|
|
||||||
ctx.fillRect(x, y, s, s);
|
|
||||||
const light = color === 'black' ? 'rgba(235,235,225,0.85)' : color === 'white' ? 'rgba(30,70,95,0.55)' : 'rgba(255,245,225,0.55)';
|
|
||||||
ctx.strokeStyle = light;
|
|
||||||
ctx.lineWidth = s * 0.05;
|
|
||||||
ctx.beginPath();
|
|
||||||
for (const [ax, ay] of [[0, 0], [1, 0], [0, 1], [1, 1]]) { ctx.moveTo(x + ax * s + (ax ? -1 : 1) * s * 0.36, y + ay * s); ctx.arc(x + ax * s, y + ay * s, s * 0.36, 0, Math.PI * 2); }
|
|
||||||
ctx.stroke();
|
|
||||||
ctx.fillStyle = light;
|
|
||||||
ctx.beginPath();
|
|
||||||
ctx.moveTo(x + s / 2, y + s * 0.22); ctx.lineTo(x + s * 0.78, y + s / 2); ctx.lineTo(x + s / 2, y + s * 0.78); ctx.lineTo(x + s * 0.22, y + s / 2);
|
|
||||||
ctx.closePath(); ctx.fill();
|
|
||||||
ctx.strokeStyle = edge; ctx.lineWidth = 2; ctx.strokeRect(x + 1, y + 1, s - 2, s - 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
function drawFace(scene, ctx, color, x, y, s) {
|
|
||||||
const f = sheetFrame(scene, color === 'first' ? FIRST_PLAYER_FRAME : tileFrame(color));
|
|
||||||
if (f) { ctx.drawImage(f.img, f.sx, f.sy, f.sw, f.sh, x, y, s, s); return; }
|
|
||||||
if (color === 'first') {
|
|
||||||
ctx.fillStyle = '#222428'; ctx.fillRect(x, y, s, s);
|
|
||||||
ctx.fillStyle = '#f4efe2';
|
|
||||||
ctx.font = `bold ${Math.round(s * 0.62)}px ${SERIF}`;
|
|
||||||
ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
|
|
||||||
ctx.fillText('1', x + s / 2, y + s / 2 + 2);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
proceduralFace(ctx, color, x, y, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── tiles ───────────────────────────────────────────────────────────────────────
|
|
||||||
function bakeTile(scene, color, glyphs) {
|
|
||||||
const { size, tile: s, ox, oy } = TILE_TEX;
|
|
||||||
const c = canvas(size, size);
|
|
||||||
const ctx = c.getContext('2d');
|
|
||||||
const r = 9;
|
|
||||||
// Shadow.
|
|
||||||
softShadow(ctx, () => { rr(ctx, ox, oy, s, s, r); ctx.fillStyle = '#000'; ctx.fill(); }, { blur: 7, dy: 4, dx: 1, color: 'rgba(0,0,0,0.5)' });
|
|
||||||
// Face, clipped to the rounded square.
|
|
||||||
ctx.save();
|
|
||||||
rr(ctx, ox, oy, s, s, r);
|
|
||||||
ctx.clip();
|
|
||||||
drawFace(scene, ctx, color, ox - 2, oy - 2, s + 4);
|
|
||||||
// Glaze: a diagonal sheen and a soft pool of light top-left.
|
|
||||||
const g = ctx.createLinearGradient(ox, oy, ox + s, oy + s);
|
|
||||||
g.addColorStop(0, 'rgba(255,255,255,0.30)');
|
|
||||||
g.addColorStop(0.38, 'rgba(255,255,255,0.06)');
|
|
||||||
g.addColorStop(0.6, 'rgba(255,255,255,0)');
|
|
||||||
g.addColorStop(1, 'rgba(0,0,0,0.16)');
|
|
||||||
ctx.fillStyle = g;
|
|
||||||
ctx.fillRect(ox, oy, s, s);
|
|
||||||
const spec = ctx.createRadialGradient(ox + s * 0.28, oy + s * 0.22, 1, ox + s * 0.28, oy + s * 0.22, s * 0.34);
|
|
||||||
spec.addColorStop(0, 'rgba(255,255,255,0.32)'); spec.addColorStop(1, 'rgba(255,255,255,0)');
|
|
||||||
ctx.fillStyle = spec;
|
|
||||||
ctx.fillRect(ox, oy, s, s);
|
|
||||||
// Bevel: light top-left, dark bottom-right.
|
|
||||||
ctx.lineWidth = 5;
|
|
||||||
ctx.strokeStyle = 'rgba(255,255,255,0.34)';
|
|
||||||
ctx.beginPath(); ctx.moveTo(ox + 2, oy + s - 4); ctx.lineTo(ox + 2, oy + 2); ctx.lineTo(ox + s - 4, oy + 2); ctx.stroke();
|
|
||||||
ctx.strokeStyle = 'rgba(0,0,0,0.30)';
|
|
||||||
ctx.beginPath(); ctx.moveTo(ox + s - 2, oy + 4); ctx.lineTo(ox + s - 2, oy + s - 2); ctx.lineTo(ox + 4, oy + s - 2); ctx.stroke();
|
|
||||||
ctx.restore();
|
|
||||||
rr(ctx, ox + 0.5, oy + 0.5, s - 1, s - 1, r);
|
|
||||||
ctx.lineWidth = 1.5;
|
|
||||||
ctx.strokeStyle = 'rgba(20,12,4,0.65)';
|
|
||||||
ctx.stroke();
|
|
||||||
if (glyphs && GLYPH[color]) {
|
|
||||||
// Badge in the lower-right corner.
|
|
||||||
const bx = ox + s - 22, by = oy + s - 22;
|
|
||||||
ctx.beginPath(); ctx.arc(bx, by, 17, 0, Math.PI * 2);
|
|
||||||
ctx.fillStyle = 'rgba(15,12,8,0.62)'; ctx.fill();
|
|
||||||
drawGlyph(ctx, GLYPH[color], bx, by, 20, { fill: '#fffaf0', stroke: 'rgba(0,0,0,0.0)', lw: 0.1 });
|
|
||||||
}
|
|
||||||
addCanvas(scene, `azul-t-${color}${glyphs ? '-g' : ''}`, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function tileKey(color, glyphs) {
|
|
||||||
if (color === 'first') return 'azul-t-first';
|
|
||||||
return `azul-t-${color}${glyphs ? '-g' : ''}`;
|
|
||||||
}
|
|
||||||
// Display size of a tile texture so its tile face measures `face` px.
|
|
||||||
export const tileDisplay = (face) => face * TILE_TEX.size / TILE_TEX.tile;
|
|
||||||
// Offset of the tile face centre from the texture centre, in face px.
|
|
||||||
export const TILE_FACE_OFF = {
|
|
||||||
x: (TILE_TEX.ox + TILE_TEX.tile / 2 - TILE_TEX.size / 2) / TILE_TEX.tile,
|
|
||||||
y: (TILE_TEX.oy + TILE_TEX.tile / 2 - TILE_TEX.size / 2) / TILE_TEX.tile,
|
|
||||||
};
|
|
||||||
|
|
||||||
// ── boards ──────────────────────────────────────────────────────────────────────
|
|
||||||
export function boardKey(size, { free = false, glyphs = false } = {}) {
|
|
||||||
return `azul-board-${size}${free ? '-free' : ''}${glyphs ? '-g' : ''}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ensureBoard(scene, size, opts = {}) {
|
|
||||||
const key = boardKey(size, opts);
|
|
||||||
if (scene.textures.exists(key)) return key;
|
|
||||||
const m = size === 'big' ? BIG : MINI;
|
|
||||||
const S = SHADOW;
|
|
||||||
const c = canvas(m.w + S * 2, m.h + S * 2);
|
|
||||||
const ctx = c.getContext('2d');
|
|
||||||
const rnd = mulberry32(size === 'big' ? 11 : 13);
|
|
||||||
const x0 = S, y0 = S;
|
|
||||||
const R = size === 'big' ? 12 : 9;
|
|
||||||
// Frame + shadow.
|
|
||||||
softShadow(ctx, () => { rr(ctx, x0, y0, m.w, m.h, R); ctx.fillStyle = '#3a2412'; ctx.fill(); }, { blur: 16, dy: 7 });
|
|
||||||
rr(ctx, x0, y0, m.w, m.h, R);
|
|
||||||
wood(ctx, x0, y0, m.w, m.h, '#6a4122', '#3e2412', rnd, 5);
|
|
||||||
// Inner plaster.
|
|
||||||
const ib = size === 'big' ? 6 : 4;
|
|
||||||
rr(ctx, x0 + ib, y0 + ib, m.w - ib * 2, m.h - ib * 2, R - 3);
|
|
||||||
const pg = ctx.createLinearGradient(0, y0, 0, y0 + m.h);
|
|
||||||
pg.addColorStop(0, '#f2e8d0'); pg.addColorStop(1, '#e2d2ac');
|
|
||||||
ctx.fillStyle = pg; ctx.fill();
|
|
||||||
ctx.save(); rr(ctx, x0 + ib, y0 + ib, m.w - ib * 2, m.h - ib * 2, R - 3); ctx.clip();
|
|
||||||
ctx.fillStyle = noisePattern(ctx, 64, 16); ctx.fillRect(x0, y0, m.w, m.h);
|
|
||||||
// Cobalt header band with a gold hairline.
|
|
||||||
const hb = m.headerH - (size === 'big' ? 8 : 6);
|
|
||||||
const hg = ctx.createLinearGradient(0, y0, 0, y0 + hb);
|
|
||||||
hg.addColorStop(0, '#265b9c'); hg.addColorStop(1, '#173f72');
|
|
||||||
ctx.fillStyle = hg; ctx.fillRect(x0, y0, m.w, hb);
|
|
||||||
// A run of tiny painted quatrefoils along the band.
|
|
||||||
ctx.fillStyle = 'rgba(255,255,255,0.10)';
|
|
||||||
for (let x = x0 + 14; x < x0 + m.w; x += 22) {
|
|
||||||
ctx.beginPath(); ctx.arc(x, y0 + hb - 6, 2.2, 0, Math.PI * 2); ctx.fill();
|
|
||||||
}
|
|
||||||
ctx.fillStyle = '#c9a24a'; ctx.fillRect(x0, y0 + hb, m.w, 2);
|
|
||||||
ctx.restore();
|
|
||||||
|
|
||||||
const bodyTop = y0 + m.headerH;
|
|
||||||
const pad = m.pad;
|
|
||||||
const cellIn = (m.cell - m.tile) / 2;
|
|
||||||
// Pattern lines: a stepped tray of recessed cells.
|
|
||||||
for (let i = 0; i < WALL_SIZE; i++) {
|
|
||||||
const cap = lineCapacity(i);
|
|
||||||
for (let col = WALL_SIZE - cap; col < WALL_SIZE; col++) {
|
|
||||||
inset(ctx, x0 + pad + col * m.cell + cellIn - 1, bodyTop + i * m.cell + cellIn - 1, m.tile + 2, 4);
|
|
||||||
}
|
|
||||||
// A cobalt guide dot in the gap, pointing at the wall.
|
|
||||||
const gx = x0 + pad + WALL_SIZE * m.cell + m.wallGap / 2;
|
|
||||||
const gy = bodyTop + i * m.cell + m.cell / 2;
|
|
||||||
ctx.fillStyle = 'rgba(29,79,143,0.55)';
|
|
||||||
ctx.beginPath(); ctx.moveTo(gx - m.wallGap * 0.22, gy - 4); ctx.lineTo(gx + m.wallGap * 0.22, gy); ctx.lineTo(gx - m.wallGap * 0.22, gy + 4); ctx.closePath(); ctx.fill();
|
|
||||||
}
|
|
||||||
// Wall: grout bed then glazed ghosts.
|
|
||||||
const wx = x0 + pad + WALL_SIZE * m.cell + m.wallGap;
|
|
||||||
rr(ctx, wx - 3, bodyTop - 3, WALL_SIZE * m.cell + 6, WALL_SIZE * m.cell + 6, 6);
|
|
||||||
ctx.fillStyle = '#c6b48c'; ctx.fill();
|
|
||||||
ctx.strokeStyle = 'rgba(90,64,30,0.5)'; ctx.lineWidth = 1.5; ctx.stroke();
|
|
||||||
for (let r = 0; r < WALL_SIZE; r++) {
|
|
||||||
for (let col = 0; col < WALL_SIZE; col++) {
|
|
||||||
const cx = wx + col * m.cell + cellIn, cy = bodyTop + r * m.cell + cellIn;
|
|
||||||
ctx.save();
|
|
||||||
rr(ctx, cx, cy, m.tile, m.tile, 4);
|
|
||||||
ctx.clip();
|
|
||||||
if (opts.free) {
|
|
||||||
const g = ctx.createLinearGradient(cx, cy, cx + m.tile, cy + m.tile);
|
|
||||||
g.addColorStop(0, '#c9ccc6'); g.addColorStop(1, '#a9ada6');
|
|
||||||
ctx.fillStyle = g; ctx.fillRect(cx, cy, m.tile, m.tile);
|
|
||||||
ctx.strokeStyle = 'rgba(255,255,255,0.35)'; ctx.lineWidth = 1;
|
|
||||||
ctx.strokeRect(cx + m.tile * 0.2, cy + m.tile * 0.2, m.tile * 0.6, m.tile * 0.6);
|
|
||||||
} else {
|
|
||||||
const color = wallColor(r, col);
|
|
||||||
drawFace(scene, ctx, color, cx, cy, m.tile);
|
|
||||||
// Wash it out toward the plaster so it reads as a ghost.
|
|
||||||
ctx.fillStyle = 'rgba(238,228,204,0.62)';
|
|
||||||
ctx.fillRect(cx, cy, m.tile, m.tile);
|
|
||||||
ctx.fillStyle = `${hex(TILE_HEX[color])}2e`;
|
|
||||||
ctx.fillRect(cx, cy, m.tile, m.tile);
|
|
||||||
if (opts.glyphs) drawGlyph(ctx, GLYPH[color], cx + m.tile / 2, cy + m.tile / 2, m.tile * 0.42, { fill: hex(TILE_HEX[color]), stroke: 'rgba(255,255,255,0.9)', lw: Math.max(1.2, m.tile * 0.06) });
|
|
||||||
}
|
|
||||||
ctx.restore();
|
|
||||||
inset(ctx, cx, cy, m.tile, 4, { fill: 'rgba(0,0,0,0)', dark: 'rgba(60,40,15,0.35)', light: 'rgba(255,250,235,0.45)' });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Floor line.
|
|
||||||
const fy = y0 + m.floorTop;
|
|
||||||
const fw = FLOOR_SIZE * (m.floorCell + m.floorGap) - m.floorGap;
|
|
||||||
rr(ctx, x0 + pad - 4, fy - m.floorLabel + 2, fw + 8, m.floorCell + m.floorLabel + 2, 6);
|
|
||||||
ctx.fillStyle = 'rgba(122,32,24,0.10)'; ctx.fill();
|
|
||||||
ctx.font = `bold ${size === 'big' ? 13 : 10}px ${SERIF}`;
|
|
||||||
ctx.textAlign = 'center'; ctx.textBaseline = 'alphabetic';
|
|
||||||
for (let k = 0; k < FLOOR_SIZE; k++) {
|
|
||||||
const fx = x0 + pad + k * (m.floorCell + m.floorGap);
|
|
||||||
inset(ctx, fx, fy, m.floorCell, 4, { fill: 'rgba(110,40,30,0.10)' });
|
|
||||||
ctx.fillStyle = '#7a2018';
|
|
||||||
ctx.fillText(`${FLOOR_PENALTIES[k]}`, fx + m.floorCell / 2, fy - 4);
|
|
||||||
}
|
|
||||||
addCanvas(scene, key, c);
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── plate, tray, bag, lid ─────────────────────────────────────────────────────
|
|
||||||
function bakePlate(scene) {
|
|
||||||
const S = PLATE_TEX, cx = S / 2, cy = S / 2 - 3, r = RING.r;
|
|
||||||
const c = canvas(S, S);
|
|
||||||
const ctx = c.getContext('2d');
|
|
||||||
softShadow(ctx, () => { ctx.beginPath(); ctx.arc(cx, cy, r, 0, Math.PI * 2); ctx.fillStyle = '#000'; ctx.fill(); }, { blur: 12, dy: 6 });
|
|
||||||
// Glazed white body.
|
|
||||||
const g = ctx.createRadialGradient(cx - r * 0.3, cy - r * 0.35, r * 0.1, cx, cy, r);
|
|
||||||
g.addColorStop(0, '#fffdf7'); g.addColorStop(0.75, '#efe9dc'); g.addColorStop(1, '#d9d0bd');
|
|
||||||
ctx.beginPath(); ctx.arc(cx, cy, r, 0, Math.PI * 2); ctx.fillStyle = g; ctx.fill();
|
|
||||||
// Cobalt rim band + painted dots and petals.
|
|
||||||
ctx.lineWidth = 7; ctx.strokeStyle = '#1f4f8f';
|
|
||||||
ctx.beginPath(); ctx.arc(cx, cy, r - 5, 0, Math.PI * 2); ctx.stroke();
|
|
||||||
ctx.lineWidth = 1.4; ctx.strokeStyle = '#2b62a8';
|
|
||||||
ctx.beginPath(); ctx.arc(cx, cy, r - 11, 0, Math.PI * 2); ctx.stroke();
|
|
||||||
ctx.fillStyle = '#f7f2e6';
|
|
||||||
for (let k = 0; k < 16; k++) {
|
|
||||||
const a = (k / 16) * Math.PI * 2;
|
|
||||||
ctx.beginPath(); ctx.arc(cx + Math.cos(a) * (r - 5), cy + Math.sin(a) * (r - 5), 1.5, 0, Math.PI * 2); ctx.fill();
|
|
||||||
}
|
|
||||||
ctx.fillStyle = 'rgba(31,79,143,0.55)';
|
|
||||||
for (let k = 0; k < 8; k++) {
|
|
||||||
const a = (k / 8) * Math.PI * 2 + Math.PI / 8;
|
|
||||||
ctx.save(); ctx.translate(cx + Math.cos(a) * (r - 15), cy + Math.sin(a) * (r - 15)); ctx.rotate(a);
|
|
||||||
ctx.beginPath(); ctx.ellipse(0, 0, 3.2, 1.5, 0, 0, Math.PI * 2); ctx.fill(); ctx.restore();
|
|
||||||
}
|
|
||||||
// Well of the plate.
|
|
||||||
const w = ctx.createRadialGradient(cx + 4, cy + 5, 2, cx, cy, r - 16);
|
|
||||||
w.addColorStop(0, 'rgba(255,255,255,0.0)'); w.addColorStop(1, 'rgba(120,100,70,0.16)');
|
|
||||||
ctx.beginPath(); ctx.arc(cx, cy, r - 16, 0, Math.PI * 2); ctx.fillStyle = w; ctx.fill();
|
|
||||||
// Glaze highlight.
|
|
||||||
ctx.beginPath(); ctx.ellipse(cx - r * 0.42, cy - r * 0.5, r * 0.32, r * 0.12, -0.6, 0, Math.PI * 2);
|
|
||||||
ctx.fillStyle = 'rgba(255,255,255,0.55)'; ctx.fill();
|
|
||||||
addCanvas(scene, 'azul-plate', c);
|
|
||||||
}
|
|
||||||
|
|
||||||
function bakeTray(scene) {
|
|
||||||
const S = SHADOW;
|
|
||||||
const c = canvas(TRAY.w + S * 2, TRAY.h + S * 2);
|
|
||||||
const ctx = c.getContext('2d');
|
|
||||||
const rnd = mulberry32(5);
|
|
||||||
softShadow(ctx, () => { rr(ctx, S, S, TRAY.w, TRAY.h, 16); ctx.fillStyle = '#000'; ctx.fill(); }, { blur: 14, dy: 6 });
|
|
||||||
rr(ctx, S, S, TRAY.w, TRAY.h, 16);
|
|
||||||
wood(ctx, S, S, TRAY.w, TRAY.h, '#8a5a30', '#5a361a', rnd, 5);
|
|
||||||
rr(ctx, S + 9, S + 9, TRAY.w - 18, TRAY.h - 18, 10);
|
|
||||||
const g = ctx.createRadialGradient(S + TRAY.w / 2, S + TRAY.h / 2, 10, S + TRAY.w / 2, S + TRAY.h / 2, TRAY.w * 0.6);
|
|
||||||
g.addColorStop(0, '#2f5a48'); g.addColorStop(1, '#1b3a2d');
|
|
||||||
ctx.fillStyle = g; ctx.fill();
|
|
||||||
ctx.save(); rr(ctx, S + 9, S + 9, TRAY.w - 18, TRAY.h - 18, 10); ctx.clip();
|
|
||||||
ctx.fillStyle = noisePattern(ctx, 48, 26); ctx.fillRect(S, S, TRAY.w, TRAY.h);
|
|
||||||
// Inner shadow under the rim.
|
|
||||||
ctx.lineWidth = 8; ctx.strokeStyle = 'rgba(0,0,0,0.35)';
|
|
||||||
rr(ctx, S + 9, S + 9, TRAY.w - 18, TRAY.h - 18, 10); ctx.stroke();
|
|
||||||
ctx.restore();
|
|
||||||
ctx.strokeStyle = 'rgba(255,220,170,0.25)'; ctx.lineWidth = 1.5;
|
|
||||||
rr(ctx, S + 2, S + 2, TRAY.w - 4, TRAY.h - 4, 14); ctx.stroke();
|
|
||||||
addCanvas(scene, 'azul-tray', c);
|
|
||||||
}
|
|
||||||
|
|
||||||
function bakeBag(scene) {
|
|
||||||
const S = SHADOW, w = BAG.w, h = BAG.h;
|
|
||||||
const c = canvas(w + S * 2, h + S * 2);
|
|
||||||
const ctx = c.getContext('2d');
|
|
||||||
const x0 = S, y0 = S;
|
|
||||||
const body = () => {
|
|
||||||
ctx.beginPath();
|
|
||||||
ctx.moveTo(x0 + w * 0.32, y0 + h * 0.22);
|
|
||||||
ctx.bezierCurveTo(x0 + w * 0.05, y0 + h * 0.35, x0 - 2, y0 + h * 0.8, x0 + w * 0.14, y0 + h * 0.95);
|
|
||||||
ctx.quadraticCurveTo(x0 + w * 0.5, y0 + h + 4, x0 + w * 0.86, y0 + h * 0.95);
|
|
||||||
ctx.bezierCurveTo(x0 + w + 2, y0 + h * 0.8, x0 + w * 0.95, y0 + h * 0.35, x0 + w * 0.68, y0 + h * 0.22);
|
|
||||||
ctx.closePath();
|
|
||||||
};
|
|
||||||
softShadow(ctx, () => { body(); ctx.fillStyle = '#000'; ctx.fill(); }, { blur: 16, dy: 8 });
|
|
||||||
body();
|
|
||||||
const g = ctx.createRadialGradient(x0 + w * 0.38, y0 + h * 0.5, 10, x0 + w * 0.5, y0 + h * 0.62, w * 0.75);
|
|
||||||
g.addColorStop(0, '#2f5f9e'); g.addColorStop(1, '#122c52');
|
|
||||||
ctx.fillStyle = g; ctx.fill();
|
|
||||||
ctx.save(); body(); ctx.clip();
|
|
||||||
// Woven texture.
|
|
||||||
ctx.strokeStyle = 'rgba(255,255,255,0.05)'; ctx.lineWidth = 1;
|
|
||||||
for (let y = y0; y < y0 + h; y += 4) { ctx.beginPath(); ctx.moveTo(x0, y); ctx.lineTo(x0 + w, y + 2); ctx.stroke(); }
|
|
||||||
ctx.fillStyle = noisePattern(ctx, 48, 30); ctx.fillRect(x0, y0, w, h);
|
|
||||||
// Folds.
|
|
||||||
ctx.strokeStyle = 'rgba(0,0,0,0.25)'; ctx.lineWidth = 3;
|
|
||||||
for (const fx of [0.3, 0.5, 0.7]) { ctx.beginPath(); ctx.moveTo(x0 + w * fx, y0 + h * 0.26); ctx.quadraticCurveTo(x0 + w * (fx + 0.06), y0 + h * 0.5, x0 + w * (fx - 0.02), y0 + h * 0.62); ctx.stroke(); }
|
|
||||||
// An embroidered tile motif.
|
|
||||||
ctx.translate(x0 + w / 2, y0 + h * 0.64); ctx.rotate(Math.PI / 4);
|
|
||||||
ctx.strokeStyle = '#e9c46a'; ctx.lineWidth = 2.5; ctx.strokeRect(-20, -20, 40, 40);
|
|
||||||
ctx.strokeStyle = 'rgba(240,235,220,0.8)'; ctx.lineWidth = 1.5; ctx.strokeRect(-12, -12, 24, 24);
|
|
||||||
ctx.restore();
|
|
||||||
// Gathered neck + drawstring.
|
|
||||||
ctx.fillStyle = '#183a6a';
|
|
||||||
ctx.beginPath(); ctx.ellipse(x0 + w / 2, y0 + h * 0.2, w * 0.2, h * 0.06, 0, 0, Math.PI * 2); ctx.fill();
|
|
||||||
ctx.fillStyle = '#244f8a';
|
|
||||||
ctx.beginPath(); ctx.moveTo(x0 + w * 0.3, y0 + h * 0.2); ctx.lineTo(x0 + w * 0.36, y0 + 4); ctx.lineTo(x0 + w * 0.64, y0 + 4); ctx.lineTo(x0 + w * 0.7, y0 + h * 0.2); ctx.closePath(); ctx.fill();
|
|
||||||
ctx.strokeStyle = '#d8b56a'; ctx.lineWidth = 4; ctx.lineCap = 'round';
|
|
||||||
ctx.beginPath(); ctx.moveTo(x0 + w * 0.3, y0 + h * 0.21); ctx.quadraticCurveTo(x0 + w / 2, y0 + h * 0.27, x0 + w * 0.7, y0 + h * 0.21); ctx.stroke();
|
|
||||||
ctx.beginPath(); ctx.moveTo(x0 + w * 0.62, y0 + h * 0.23); ctx.quadraticCurveTo(x0 + w * 0.8, y0 + h * 0.34, x0 + w * 0.74, y0 + h * 0.46); ctx.stroke();
|
|
||||||
ctx.beginPath(); ctx.arc(x0 + w * 0.74, y0 + h * 0.47, 4, 0, Math.PI * 2); ctx.fillStyle = '#d8b56a'; ctx.fill();
|
|
||||||
addCanvas(scene, 'azul-bag', c);
|
|
||||||
}
|
|
||||||
|
|
||||||
function bakeLid(scene) {
|
|
||||||
const S = SHADOW, w = LID.w, h = LID.h;
|
|
||||||
const c = canvas(w + S * 2, h + S * 2);
|
|
||||||
const ctx = c.getContext('2d');
|
|
||||||
const x0 = S, y0 = S;
|
|
||||||
softShadow(ctx, () => { rr(ctx, x0, y0, w, h, 8); ctx.fillStyle = '#000'; ctx.fill(); }, { blur: 14, dy: 6 });
|
|
||||||
// Cardboard rim printed cobalt.
|
|
||||||
rr(ctx, x0, y0, w, h, 8);
|
|
||||||
const g = ctx.createLinearGradient(0, y0, 0, y0 + h);
|
|
||||||
g.addColorStop(0, '#2a62a6'); g.addColorStop(1, '#173c6c');
|
|
||||||
ctx.fillStyle = g; ctx.fill();
|
|
||||||
ctx.strokeStyle = '#c9a24a'; ctx.lineWidth = 2; rr(ctx, x0 + 3, y0 + 3, w - 6, h - 6, 6); ctx.stroke();
|
|
||||||
// Interior.
|
|
||||||
rr(ctx, x0 + 12, y0 + 12, w - 24, h - 24, 4);
|
|
||||||
const ig = ctx.createLinearGradient(0, y0 + 12, 0, y0 + h - 12);
|
|
||||||
ig.addColorStop(0, '#2a2016'); ig.addColorStop(1, '#4a3b28');
|
|
||||||
ctx.fillStyle = ig; ctx.fill();
|
|
||||||
ctx.save(); rr(ctx, x0 + 12, y0 + 12, w - 24, h - 24, 4); ctx.clip();
|
|
||||||
ctx.fillStyle = noisePattern(ctx, 48, 24); ctx.fillRect(x0, y0, w, h);
|
|
||||||
ctx.lineWidth = 10; ctx.strokeStyle = 'rgba(0,0,0,0.4)'; rr(ctx, x0 + 12, y0 + 12, w - 24, h - 24, 4); ctx.stroke();
|
|
||||||
ctx.restore();
|
|
||||||
addCanvas(scene, 'azul-lid', c);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── panels and the order book ────────────────────────────────────────────────
|
|
||||||
export function ensurePanel(scene, name, w, h, { header = true } = {}) {
|
|
||||||
const key = `azul-panel-${name}`;
|
|
||||||
if (scene.textures.exists(key)) return key;
|
|
||||||
const S = SHADOW;
|
|
||||||
const c = canvas(w + S * 2, h + S * 2);
|
|
||||||
const ctx = c.getContext('2d');
|
|
||||||
const rnd = mulberry32(w * 7 + h);
|
|
||||||
softShadow(ctx, () => { rr(ctx, S, S, w, h, 12); ctx.fillStyle = '#000'; ctx.fill(); }, { blur: 16, dy: 7 });
|
|
||||||
rr(ctx, S, S, w, h, 12);
|
|
||||||
wood(ctx, S, S, w, h, '#6a4122', '#3e2412', rnd, 5);
|
|
||||||
rr(ctx, S + 7, S + 7, w - 14, h - 14, 8);
|
|
||||||
const pg = ctx.createLinearGradient(0, S, 0, S + h);
|
|
||||||
pg.addColorStop(0, '#f3ead4'); pg.addColorStop(1, '#e4d5b2');
|
|
||||||
ctx.fillStyle = pg; ctx.fill();
|
|
||||||
ctx.save(); rr(ctx, S + 7, S + 7, w - 14, h - 14, 8); ctx.clip();
|
|
||||||
ctx.fillStyle = noisePattern(ctx, 64, 16); ctx.fillRect(S, S, w, h);
|
|
||||||
if (header) {
|
|
||||||
// Azulejo corner tiles.
|
|
||||||
for (const [cx, cy] of [[S + 7, S + 7], [S + w - 7 - 26, S + 7]]) {
|
|
||||||
ctx.fillStyle = '#f7f1e3'; ctx.fillRect(cx, cy, 26, 26);
|
|
||||||
ctx.strokeStyle = COBALT; ctx.lineWidth = 2;
|
|
||||||
ctx.beginPath(); ctx.arc(cx + 13, cy + 13, 8, 0, Math.PI * 2); ctx.stroke();
|
|
||||||
ctx.beginPath(); ctx.moveTo(cx + 13, cy + 2); ctx.lineTo(cx + 24, cy + 13); ctx.lineTo(cx + 13, cy + 24); ctx.lineTo(cx + 2, cy + 13); ctx.closePath(); ctx.stroke();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ctx.restore();
|
|
||||||
ctx.strokeStyle = 'rgba(201,162,74,0.8)'; ctx.lineWidth = 1.5;
|
|
||||||
rr(ctx, S + 11, S + 11, w - 22, h - 22, 6); ctx.stroke();
|
|
||||||
addCanvas(scene, key, c);
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
function bakeNotepad(scene) {
|
|
||||||
const S = SHADOW, w = NOTEPAD.w, h = NOTEPAD.h;
|
|
||||||
const c = canvas(w + S * 2, h + S * 2);
|
|
||||||
const ctx = c.getContext('2d');
|
|
||||||
const x0 = S, y0 = S;
|
|
||||||
softShadow(ctx, () => { ctx.fillStyle = '#000'; ctx.fillRect(x0, y0 + 6, w, h - 6); }, { blur: 14, dy: 6 });
|
|
||||||
// Leather spine.
|
|
||||||
rr(ctx, x0, y0, w, 30, 6);
|
|
||||||
ctx.fillStyle = '#6b2a1a'; ctx.fill();
|
|
||||||
ctx.fillStyle = 'rgba(255,220,170,0.25)'; ctx.fillRect(x0 + 6, y0 + 6, w - 12, 2);
|
|
||||||
// Paper.
|
|
||||||
ctx.fillStyle = '#f6f0df';
|
|
||||||
ctx.fillRect(x0 + 6, y0 + 26, w - 12, h - 28);
|
|
||||||
ctx.save(); ctx.beginPath(); ctx.rect(x0 + 6, y0 + 26, w - 12, h - 28); ctx.clip();
|
|
||||||
ctx.fillStyle = noisePattern(ctx, 64, 14); ctx.fillRect(x0, y0, w, h);
|
|
||||||
ctx.strokeStyle = 'rgba(60,110,170,0.25)'; ctx.lineWidth = 1;
|
|
||||||
for (let y = y0 + 70; y < y0 + h - 6; y += 26) { ctx.beginPath(); ctx.moveTo(x0 + 6, y); ctx.lineTo(x0 + w - 6, y); ctx.stroke(); }
|
|
||||||
ctx.strokeStyle = 'rgba(190,60,50,0.35)';
|
|
||||||
ctx.beginPath(); ctx.moveTo(x0 + 44, y0 + 26); ctx.lineTo(x0 + 44, y0 + h); ctx.stroke();
|
|
||||||
ctx.restore();
|
|
||||||
// Rings.
|
|
||||||
for (let x = x0 + 40; x < x0 + w - 20; x += 48) {
|
|
||||||
ctx.beginPath(); ctx.arc(x, y0 + 26, 5, 0, Math.PI * 2); ctx.fillStyle = '#b9b2a0'; ctx.fill();
|
|
||||||
ctx.strokeStyle = '#6d675a'; ctx.lineWidth = 1.5; ctx.stroke();
|
|
||||||
}
|
|
||||||
addCanvas(scene, 'azul-notepad', c);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── the room ──────────────────────────────────────────────────────────────────
|
|
||||||
function azulejo(ctx, x, y, s, rnd) {
|
|
||||||
ctx.fillStyle = '#f5f0e4';
|
|
||||||
ctx.fillRect(x, y, s, s);
|
|
||||||
ctx.fillStyle = noisePattern(ctx, 32, 14); ctx.fillRect(x, y, s, s);
|
|
||||||
ctx.strokeStyle = COBALT; ctx.fillStyle = COBALT;
|
|
||||||
ctx.lineWidth = s * 0.06;
|
|
||||||
// Quarter arcs at each corner join into circles across tiles.
|
|
||||||
for (const [ax, ay] of [[0, 0], [1, 0], [0, 1], [1, 1]]) {
|
|
||||||
ctx.beginPath(); ctx.arc(x + ax * s, y + ay * s, s * 0.42, 0, Math.PI * 2); ctx.stroke();
|
|
||||||
}
|
|
||||||
ctx.beginPath(); ctx.moveTo(x + s / 2, y + s * 0.16); ctx.lineTo(x + s * 0.84, y + s / 2); ctx.lineTo(x + s / 2, y + s * 0.84); ctx.lineTo(x + s * 0.16, y + s / 2); ctx.closePath();
|
|
||||||
ctx.globalAlpha = 0.85; ctx.fill(); ctx.globalAlpha = 1;
|
|
||||||
ctx.fillStyle = '#e8b64a';
|
|
||||||
ctx.beginPath(); ctx.arc(x + s / 2, y + s / 2, s * 0.1, 0, Math.PI * 2); ctx.fill();
|
|
||||||
ctx.strokeStyle = `rgba(120,100,70,${0.25 + rnd() * 0.2})`; ctx.lineWidth = 1;
|
|
||||||
ctx.strokeRect(x + 0.5, y + 0.5, s - 1, s - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function bakeRoom(scene) {
|
|
||||||
const c = canvas(W, H);
|
|
||||||
const ctx = c.getContext('2d');
|
|
||||||
const rnd = mulberry32(31);
|
|
||||||
// Oak workbench: long planks.
|
|
||||||
const plankH = 120;
|
|
||||||
for (let y = WAINSCOT.h, i = 0; y < H; y += plankH, i++) {
|
|
||||||
const t = i % 2 ? ['#8b5e34', '#704623'] : ['#966a3d', '#7a4f29'];
|
|
||||||
ctx.beginPath(); ctx.rect(0, y, W, plankH);
|
|
||||||
wood(ctx, 0, y, W, plankH, t[0], t[1], rnd, 6);
|
|
||||||
ctx.fillStyle = 'rgba(30,16,6,0.55)'; ctx.fillRect(0, y, W, 2);
|
|
||||||
ctx.fillStyle = 'rgba(255,220,170,0.08)'; ctx.fillRect(0, y + 2, W, 1);
|
|
||||||
// Butt joints.
|
|
||||||
const jx = (i * 613) % 1500 + 200;
|
|
||||||
ctx.fillStyle = 'rgba(30,16,6,0.4)'; ctx.fillRect(jx, y, 2, plankH);
|
|
||||||
}
|
|
||||||
// Wear: a few scratches and old glaze spatters.
|
|
||||||
for (let k = 0; k < 140; k++) {
|
|
||||||
const x = rnd() * W, y = WAINSCOT.h + rnd() * (H - WAINSCOT.h);
|
|
||||||
ctx.strokeStyle = `rgba(255,230,190,${0.03 + rnd() * 0.05})`; ctx.lineWidth = 1;
|
|
||||||
ctx.beginPath(); ctx.moveTo(x, y); ctx.lineTo(x + 10 + rnd() * 40, y + (rnd() - 0.5) * 6); ctx.stroke();
|
|
||||||
}
|
|
||||||
for (let k = 0; k < 26; k++) {
|
|
||||||
const x = rnd() * W, y = WAINSCOT.h + rnd() * (H - WAINSCOT.h);
|
|
||||||
ctx.fillStyle = rnd() < 0.6 ? 'rgba(40,90,160,0.16)' : 'rgba(230,180,70,0.14)';
|
|
||||||
ctx.beginPath(); ctx.arc(x, y, 1.5 + rnd() * 3.5, 0, Math.PI * 2); ctx.fill();
|
|
||||||
}
|
|
||||||
// Lamp pool + vignette.
|
|
||||||
const lamp = ctx.createRadialGradient(960, 520, 60, 960, 560, 1150);
|
|
||||||
lamp.addColorStop(0, 'rgba(255,214,150,0.22)');
|
|
||||||
lamp.addColorStop(0.45, 'rgba(255,190,120,0.06)');
|
|
||||||
lamp.addColorStop(1, 'rgba(10,4,0,0.62)');
|
|
||||||
ctx.fillStyle = lamp; ctx.fillRect(0, WAINSCOT.h, W, H - WAINSCOT.h);
|
|
||||||
// Wainscot: a band of azulejos with an ochre border.
|
|
||||||
const s = WAINSCOT.h - 8;
|
|
||||||
for (let x = -((W % s) / 2); x < W; x += s) azulejo(ctx, x, 0, s, rnd);
|
|
||||||
ctx.fillStyle = '#c9a24a'; ctx.fillRect(0, s, W, 3);
|
|
||||||
ctx.fillStyle = '#5a3a1c'; ctx.fillRect(0, s + 3, W, WAINSCOT.h - s - 3);
|
|
||||||
ctx.fillStyle = 'rgba(0,0,0,0.35)'; ctx.fillRect(0, WAINSCOT.h, W, 4);
|
|
||||||
// Title cartouche.
|
|
||||||
const tw = 230, th = 50, tx = TITLE.x - tw / 2, ty = TITLE.y - th / 2;
|
|
||||||
softShadow(ctx, () => { rr(ctx, tx, ty, tw, th, 10); ctx.fillStyle = '#000'; ctx.fill(); }, { blur: 10, dy: 4 });
|
|
||||||
rr(ctx, tx, ty, tw, th, 10);
|
|
||||||
ctx.fillStyle = '#f6f0e1'; ctx.fill();
|
|
||||||
ctx.lineWidth = 3; ctx.strokeStyle = COBALT; rr(ctx, tx + 4, ty + 4, tw - 8, th - 8, 7); ctx.stroke();
|
|
||||||
ctx.lineWidth = 1; ctx.strokeStyle = '#c9a24a'; rr(ctx, tx + 8, ty + 8, tw - 16, th - 16, 5); ctx.stroke();
|
|
||||||
ctx.font = `32px ${DISPLAY}`;
|
|
||||||
ctx.fillStyle = COBALT; ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
|
|
||||||
ctx.fillText('AZUL', TITLE.x, TITLE.y + 2);
|
|
||||||
// A burlap mat under the bag and lid.
|
|
||||||
ctx.save();
|
|
||||||
rr(ctx, 70, 380, 450, 250, 18);
|
|
||||||
ctx.fillStyle = 'rgba(176,146,98,0.55)'; ctx.fill();
|
|
||||||
ctx.clip();
|
|
||||||
ctx.strokeStyle = 'rgba(90,64,30,0.25)'; ctx.lineWidth = 1;
|
|
||||||
for (let x = 70; x < 520; x += 5) { ctx.beginPath(); ctx.moveTo(x, 380); ctx.lineTo(x, 630); ctx.stroke(); }
|
|
||||||
for (let y = 380; y < 630; y += 5) { ctx.beginPath(); ctx.moveTo(70, y); ctx.lineTo(520, y); ctx.stroke(); }
|
|
||||||
ctx.restore();
|
|
||||||
addCanvas(scene, 'azul-room', c);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The wainscot alone (kept over a chosen playfield cloth).
|
|
||||||
function bakeWainscot(scene) {
|
|
||||||
const c = canvas(W, WAINSCOT.h + 4);
|
|
||||||
const ctx = c.getContext('2d');
|
|
||||||
const room = scene.textures.get('azul-room').getSourceImage();
|
|
||||||
ctx.drawImage(room, 0, 0, W, WAINSCOT.h + 4, 0, 0, W, WAINSCOT.h + 4);
|
|
||||||
addCanvas(scene, 'azul-wainscot', c);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── FX ──────────────────────────────────────────────────────────────────────────
|
|
||||||
function bakeFx(scene) {
|
|
||||||
const radial = (key, s, stops) => {
|
|
||||||
const c = canvas(s, s); const ctx = c.getContext('2d');
|
|
||||||
const g = ctx.createRadialGradient(s / 2, s / 2, 0, s / 2, s / 2, s / 2);
|
|
||||||
stops.forEach(([o, col]) => g.addColorStop(o, col));
|
|
||||||
ctx.fillStyle = g; ctx.fillRect(0, 0, s, s);
|
|
||||||
addCanvas(scene, key, c);
|
|
||||||
};
|
|
||||||
radial('azul-glow', 128, [[0, 'rgba(255,255,255,1)'], [0.4, 'rgba(255,255,255,0.45)'], [1, 'rgba(255,255,255,0)']]);
|
|
||||||
radial('azul-dust', 24, [[0, 'rgba(255,240,210,0.9)'], [1, 'rgba(255,240,210,0)']]);
|
|
||||||
{
|
|
||||||
const s = 32, c = canvas(s, s), ctx = c.getContext('2d');
|
|
||||||
ctx.translate(s / 2, s / 2); ctx.fillStyle = '#fff';
|
|
||||||
ctx.beginPath();
|
|
||||||
for (let k = 0; k < 8; k++) { const r = k % 2 ? 4 : 15; const a = (k / 8) * Math.PI * 2; ctx.lineTo(Math.cos(a) * r, Math.sin(a) * r); }
|
|
||||||
ctx.closePath(); ctx.fill();
|
|
||||||
addCanvas(scene, 'azul-spark', c);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
const c = canvas(64, 128), ctx = c.getContext('2d');
|
|
||||||
const g = ctx.createLinearGradient(0, 0, 64, 0);
|
|
||||||
g.addColorStop(0, 'rgba(255,255,255,0)'); g.addColorStop(0.5, 'rgba(255,255,255,0.85)'); g.addColorStop(1, 'rgba(255,255,255,0)');
|
|
||||||
ctx.fillStyle = g; ctx.fillRect(0, 0, 64, 128);
|
|
||||||
addCanvas(scene, 'azul-glint', c);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// A shard for the floor-line "crack".
|
|
||||||
const c = canvas(16, 16), ctx = c.getContext('2d');
|
|
||||||
ctx.fillStyle = '#fff';
|
|
||||||
ctx.beginPath(); ctx.moveTo(2, 3); ctx.lineTo(14, 1); ctx.lineTo(10, 14); ctx.closePath(); ctx.fill();
|
|
||||||
addCanvas(scene, 'azul-shard', c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── entry point ──────────────────────────────────────────────────────────────────
|
|
||||||
// Waits (briefly) for the display font so canvas text bakes in the right face.
|
|
||||||
export async function prepareAzulArt(scene, { glyphs = false, free = false } = {}) {
|
|
||||||
try {
|
|
||||||
if (document.fonts?.load) {
|
|
||||||
await Promise.race([
|
|
||||||
Promise.all([document.fonts.load('20px Caesar'), document.fonts.load('14px "Julius Sans One"')]),
|
|
||||||
new Promise((res) => setTimeout(res, 1200)),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
} catch (_) { /* fall back to Georgia */ }
|
|
||||||
bakeRoom(scene);
|
|
||||||
bakeWainscot(scene);
|
|
||||||
for (const c of COLORS) { bakeTile(scene, c, false); bakeTile(scene, c, true); }
|
|
||||||
bakeTile(scene, 'first', false);
|
|
||||||
ensureBoard(scene, 'big', { glyphs, free });
|
|
||||||
ensureBoard(scene, 'mini', { glyphs, free });
|
|
||||||
bakePlate(scene);
|
|
||||||
bakeTray(scene);
|
|
||||||
bakeBag(scene);
|
|
||||||
bakeLid(scene);
|
|
||||||
bakeNotepad(scene);
|
|
||||||
ensurePanel(scene, 'tracker', TRACKER.w, TRACKER.h);
|
|
||||||
ensurePanel(scene, 'action', ACTION.w, ACTION.h);
|
|
||||||
ensurePanel(scene, 'scores', SCORES.w, SCORES.h);
|
|
||||||
bakeFx(scene);
|
|
||||||
}
|
|
||||||
|
|
@ -1,141 +0,0 @@
|
||||||
// AzulDialogs.js — the workshop's pop-ups: a cream plaster card in a walnut
|
|
||||||
// frame with a cobalt hairline. Each opener returns { close() } and swallows
|
|
||||||
// clicks beneath it.
|
|
||||||
//
|
|
||||||
// openPauseMenu resume · opponent speed · helpers · wall variant · rules · new game · leave
|
|
||||||
// openLog the full order book (wheel scroll)
|
|
||||||
// confirmBox yes / no
|
|
||||||
|
|
||||||
import { GAME_WIDTH, GAME_HEIGHT } from '../../config.js';
|
|
||||||
import { Button } from '../../ui/Button.js';
|
|
||||||
import { SERIF, DISPLAY, COBALT, INK } from './AzulArt.js';
|
|
||||||
|
|
||||||
export function frame(scene, x, y, w, h, depth) {
|
|
||||||
const g = scene.add.graphics().setDepth(depth);
|
|
||||||
g.fillStyle(0x000000, 0.45).fillRoundedRect(x + 4, y + 8, w, h, 14);
|
|
||||||
g.fillStyle(0x4a2d16, 1).fillRoundedRect(x, y, w, h, 14);
|
|
||||||
g.lineStyle(2, 0xc9a24a, 0.9).strokeRoundedRect(x + 4, y + 4, w - 8, h - 8, 11);
|
|
||||||
g.fillStyle(0xf3ead4, 1).fillRoundedRect(x + 10, y + 10, w - 20, h - 20, 8);
|
|
||||||
g.lineStyle(2, 0x1d4f8f, 0.8).strokeRoundedRect(x + 16, y + 16, w - 32, h - 32, 6);
|
|
||||||
return g;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function blocker(scene, depth, alpha = 0) {
|
|
||||||
return scene.add.rectangle(GAME_WIDTH / 2, GAME_HEIGHT / 2, GAME_WIDTH, GAME_HEIGHT, 0x000000, alpha)
|
|
||||||
.setDepth(depth).setInteractive();
|
|
||||||
}
|
|
||||||
|
|
||||||
export function title(scene, x, y, text, depth, size = 26) {
|
|
||||||
return scene.add.text(x, y, text, { fontFamily: DISPLAY, fontSize: `${size}px`, color: COBALT, align: 'center' })
|
|
||||||
.setOrigin(0.5).setDepth(depth);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function handle(objs, onClose) {
|
|
||||||
let closed = false;
|
|
||||||
return {
|
|
||||||
objs,
|
|
||||||
close() {
|
|
||||||
if (closed) return;
|
|
||||||
closed = true;
|
|
||||||
objs.forEach((o) => o?.destroy?.());
|
|
||||||
onClose?.();
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const onOff = (v) => (v ? 'On' : 'Off');
|
|
||||||
const PACE_LABEL = { relaxed: 'Relaxed', normal: 'Normal', fast: 'Fast' };
|
|
||||||
|
|
||||||
// ── pause / settings ──────────────────────────────────────────────────────────────
|
|
||||||
export function openPauseMenu(scene, { settings, variantNow, depth, onChange, onRules, onNewGame, onLeave, onClose }) {
|
|
||||||
const objs = [blocker(scene, depth - 1, 0.5)];
|
|
||||||
const w = 500, h = 720;
|
|
||||||
const x = GAME_WIDTH / 2 - w / 2, y = GAME_HEIGHT / 2 - h / 2;
|
|
||||||
objs.push(frame(scene, x, y, w, h, depth));
|
|
||||||
objs.push(title(scene, x + w / 2, y + 50, 'The Workshop', depth + 1, 28));
|
|
||||||
const cx = x + w / 2;
|
|
||||||
let hRef = null;
|
|
||||||
const variantLabel = () => {
|
|
||||||
const v = settings.variant === 'free' ? 'Free (grey) wall' : 'Printed wall';
|
|
||||||
return `Wall: ${v}${settings.variant !== variantNow ? ' · next game' : ''}`;
|
|
||||||
};
|
|
||||||
const rows = [
|
|
||||||
['Resume', () => hRef.close(), 0x1d4f8f],
|
|
||||||
[() => `Opponent speed: ${PACE_LABEL[settings.pace]}`, () => {
|
|
||||||
const order = ['relaxed', 'normal', 'fast'];
|
|
||||||
onChange('pace', order[(order.indexOf(settings.pace) + 1) % order.length]);
|
|
||||||
}],
|
|
||||||
[() => `Move preview: ${onOff(settings.preview)}`, () => onChange('preview', !settings.preview)],
|
|
||||||
[() => `Undo last move: ${onOff(settings.undo)}`, () => onChange('undo', !settings.undo)],
|
|
||||||
[() => `Tile tracker: ${onOff(settings.tracker)}`, () => onChange('tracker', !settings.tracker)],
|
|
||||||
[() => `Bonus hints on boards: ${onOff(settings.bonusHints)}`, () => onChange('bonusHints', !settings.bonusHints)],
|
|
||||||
[() => `Colour-blind symbols: ${onOff(settings.glyphs)}`, () => onChange('glyphs', !settings.glyphs)],
|
|
||||||
[variantLabel, () => onChange('variant', settings.variant === 'free' ? 'standard' : 'free')],
|
|
||||||
['How to Play', () => onRules()],
|
|
||||||
['New Game', () => { hRef.close(); onNewGame(); }, 0x6a4a1a],
|
|
||||||
['Leave Table', () => { hRef.close(); onLeave(); }, 0x7a2a1a],
|
|
||||||
];
|
|
||||||
rows.forEach(([label, fn, bg], i) => {
|
|
||||||
const text = typeof label === 'function' ? label() : label;
|
|
||||||
const btn = new Button(scene, cx, y + 106 + i * 52, text, () => {
|
|
||||||
fn();
|
|
||||||
if (typeof label === 'function') btn.setLabel(label());
|
|
||||||
}, { width: 400, height: 44, fontSize: 17, bg: bg ?? 0x5a3820 }).setDepth(depth + 2);
|
|
||||||
objs.push(btn);
|
|
||||||
});
|
|
||||||
objs.push(scene.add.text(cx, y + h - 34, 'Keys: 1–9 plates · C centre · ←/→ colour · ↑/↓ line · Enter place · F floor · Z undo · L log', {
|
|
||||||
fontFamily: SERIF, fontSize: '12px', fontStyle: 'italic', color: '#5a4428', align: 'center', wordWrap: { width: w - 60 },
|
|
||||||
}).setOrigin(0.5).setDepth(depth + 1));
|
|
||||||
hRef = handle(objs, onClose);
|
|
||||||
return hRef;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── log ────────────────────────────────────────────────────────────────────────────
|
|
||||||
export function openLog(scene, { log, depth, onClose }) {
|
|
||||||
const objs = [blocker(scene, depth - 1, 0.5)];
|
|
||||||
const w = 760, h = 700;
|
|
||||||
const x = GAME_WIDTH / 2 - w / 2, y = GAME_HEIGHT / 2 - h / 2;
|
|
||||||
objs.push(frame(scene, x, y, w, h, depth));
|
|
||||||
objs.push(title(scene, x + w / 2, y + 48, 'Order Book', depth + 1, 28));
|
|
||||||
const viewY = y + 84, viewH = h - 160;
|
|
||||||
const lines = log.slice().reverse();
|
|
||||||
const body = scene.add.text(x + 44, viewY, lines.join('\n'), {
|
|
||||||
fontFamily: SERIF, fontSize: '16px', color: '#1d3f6e', lineSpacing: 8, wordWrap: { width: w - 88 },
|
|
||||||
}).setDepth(depth + 1);
|
|
||||||
const maskG = scene.make.graphics({ x: 0, y: 0, add: false });
|
|
||||||
maskG.fillStyle(0xffffff).fillRect(x + 20, viewY, w - 40, viewH);
|
|
||||||
body.setMask(maskG.createGeometryMask());
|
|
||||||
objs.push(body, { destroy: () => maskG.destroy() });
|
|
||||||
const maxScroll = Math.max(0, body.height - viewH);
|
|
||||||
let off = 0;
|
|
||||||
const onWheel = (_p, _o, _dx, dy) => { off = Math.max(0, Math.min(maxScroll, off + dy * 0.6)); body.y = viewY - off; };
|
|
||||||
scene.input.on('wheel', onWheel);
|
|
||||||
objs.push({ destroy: () => scene.input.off('wheel', onWheel) });
|
|
||||||
if (maxScroll > 0) {
|
|
||||||
objs.push(scene.add.text(x + w - 44, viewY + viewH + 8, 'newest first · scroll for more ↓', {
|
|
||||||
fontFamily: SERIF, fontSize: '12px', fontStyle: 'italic', color: '#5a4428',
|
|
||||||
}).setOrigin(1, 0).setDepth(depth + 1));
|
|
||||||
}
|
|
||||||
let hRef = null;
|
|
||||||
objs.push(new Button(scene, x + w / 2, y + h - 42, 'Close', () => hRef.close(), { width: 200, height: 44, fontSize: 18, bg: 0x5a3820 }).setDepth(depth + 2));
|
|
||||||
objs[0].on('pointerdown', () => hRef.close());
|
|
||||||
hRef = handle(objs, onClose);
|
|
||||||
return hRef;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── confirm ────────────────────────────────────────────────────────────────────────
|
|
||||||
export function confirmBox(scene, { heading, text, yes = 'Yes', no = 'Cancel', depth, onYes, onNo }) {
|
|
||||||
const objs = [blocker(scene, depth - 1, 0.5)];
|
|
||||||
const w = 500, h = 240;
|
|
||||||
const x = GAME_WIDTH / 2 - w / 2, y = GAME_HEIGHT / 2 - h / 2;
|
|
||||||
objs.push(frame(scene, x, y, w, h, depth));
|
|
||||||
objs.push(title(scene, x + w / 2, y + 48, heading, depth + 1, 24));
|
|
||||||
objs.push(scene.add.text(x + w / 2, y + 104, text, {
|
|
||||||
fontFamily: SERIF, fontSize: '16px', color: INK, align: 'center', wordWrap: { width: w - 70 },
|
|
||||||
}).setOrigin(0.5).setDepth(depth + 1));
|
|
||||||
let hRef = null;
|
|
||||||
objs.push(new Button(scene, x + w / 2 - 112, y + h - 52, yes, () => { hRef.close(); onYes?.(); }, { width: 196, height: 46, fontSize: 18, bg: 0x1d4f8f }).setDepth(depth + 2));
|
|
||||||
objs.push(new Button(scene, x + w / 2 + 112, y + h - 52, no, () => { hRef.close(); onNo?.(); }, { width: 196, height: 46, fontSize: 18, bg: 0x5a3820 }).setDepth(depth + 2));
|
|
||||||
hRef = handle(objs);
|
|
||||||
return hRef;
|
|
||||||
}
|
|
||||||
|
|
@ -1,127 +0,0 @@
|
||||||
// AzulEndScreen.js — the final tally, shown after the end-game bonuses have
|
|
||||||
// been counted on the boards. A plaster card in a walnut frame with:
|
|
||||||
// • one row per player: rank, name, total, points by source (wall, floor,
|
|
||||||
// rows, columns, colours), their finished wall in miniature, a few stats
|
|
||||||
// • a points-by-round chart
|
|
||||||
// • Play Again · View Table (hide the card to look at the boards) · Leave
|
|
||||||
|
|
||||||
import { GAME_WIDTH, GAME_HEIGHT } from '../../config.js';
|
|
||||||
import { Button } from '../../ui/Button.js';
|
|
||||||
import { TILE_HEX, WALL_SIZE } from './AzulData.js';
|
|
||||||
import { finalRanking, cellColor } from './AzulLogic.js';
|
|
||||||
import { SERIF, DISPLAY, COBALT, INK } from './AzulArt.js';
|
|
||||||
import { frame, blocker } from './AzulDialogs.js';
|
|
||||||
|
|
||||||
export const SEAT_INK = [0x1d4f8f, 0xa7311d, 0xb07a12, 0x3c7a3a];
|
|
||||||
const hexStr = (n) => `#${n.toString(16).padStart(6, '0')}`;
|
|
||||||
|
|
||||||
export function showAzulEndScreen(scene, { depth, onPlayAgain, onLeave, onHidePortraits, onShowPortraits }) {
|
|
||||||
const gs = scene.gs;
|
|
||||||
const ranking = finalRanking(gs);
|
|
||||||
const objs = [];
|
|
||||||
const add = (o) => { objs.push(o); return o; };
|
|
||||||
const n = ranking.length;
|
|
||||||
const w = 1280, rowH = 92, chartH = 210;
|
|
||||||
const h = 150 + n * rowH + chartH + 96;
|
|
||||||
const x = GAME_WIDTH / 2 - w / 2, y = Math.max(16, GAME_HEIGHT / 2 - h / 2);
|
|
||||||
|
|
||||||
add(blocker(scene, depth - 1, 0.55));
|
|
||||||
add(frame(scene, x, y, w, h, depth));
|
|
||||||
const top = ranking[0];
|
|
||||||
const won = top.seat === 0;
|
|
||||||
const tied = ranking.length > 1 && ranking[1].score === top.score && ranking[1].rows === top.rows;
|
|
||||||
add(scene.add.text(x + w / 2, y + 52, tied ? 'A shared victory!' : won ? 'Your wall is the finest!' : `${top.name} wins the commission`, {
|
|
||||||
fontFamily: DISPLAY, fontSize: '34px', color: won ? '#b07a12' : COBALT,
|
|
||||||
}).setOrigin(0.5).setDepth(depth + 1));
|
|
||||||
|
|
||||||
// Column heads.
|
|
||||||
const cols = [
|
|
||||||
['Wall', 520], ['Floor', 590], ['Rows', 660], ['Columns', 740], ['Colours', 826], ['Total', 912],
|
|
||||||
];
|
|
||||||
const headY = y + 104;
|
|
||||||
cols.forEach(([t, cx]) => add(scene.add.text(x + cx, headY, t, { fontFamily: SERIF, fontSize: '14px', fontStyle: 'italic', color: '#6b5226' }).setOrigin(0.5).setDepth(depth + 1)));
|
|
||||||
add(scene.add.text(x + 1010, headY, 'Wall', { fontFamily: SERIF, fontSize: '14px', fontStyle: 'italic', color: '#6b5226' }).setOrigin(0.5).setDepth(depth + 1));
|
|
||||||
add(scene.add.text(x + 1150, headY, 'Stats', { fontFamily: SERIF, fontSize: '14px', fontStyle: 'italic', color: '#6b5226' }).setOrigin(0.5).setDepth(depth + 1));
|
|
||||||
|
|
||||||
ranking.forEach((r, i) => {
|
|
||||||
const p = gs.players[r.seat];
|
|
||||||
const st = p.stats;
|
|
||||||
const ry = y + 150 + i * rowH;
|
|
||||||
const g = add(scene.add.graphics().setDepth(depth + 1));
|
|
||||||
g.fillStyle(i === 0 ? 0xffe7a8 : r.seat === 0 ? 0xe6ecf4 : 0xffffff, i === 0 ? 0.85 : 0.5).fillRoundedRect(x + 36, ry - 38, w - 72, rowH - 12, 8);
|
|
||||||
g.fillStyle(SEAT_INK[r.seat % SEAT_INK.length], 1).fillRect(x + 36, ry - 38, 6, rowH - 12);
|
|
||||||
add(scene.add.text(x + 70, ry, `${i + 1}`, { fontFamily: 'Righteous', fontSize: '30px', color: i === 0 ? '#b07a12' : '#6b5226' }).setOrigin(0.5).setDepth(depth + 2));
|
|
||||||
add(scene.add.text(x + 100, ry - 12, r.seat === 0 ? `${p.name} (you)` : p.name, { fontFamily: SERIF, fontSize: '22px', color: INK }).setOrigin(0, 0.5).setDepth(depth + 2));
|
|
||||||
add(scene.add.text(x + 100, ry + 16, `${r.rows} row${r.rows === 1 ? '' : 's'} complete`, { fontFamily: SERIF, fontSize: '13px', fontStyle: 'italic', color: '#6b5226' }).setOrigin(0, 0.5).setDepth(depth + 2));
|
|
||||||
const b = gs.roundSummary?.[r.seat]?.endBonuses ?? { rowPts: 0, colPts: 0, colorPts: 0 };
|
|
||||||
const vals = [`+${st.placementPts}`, st.floorLost ? `−${st.floorLost}` : '0', `+${b.rowPts}`, `+${b.colPts}`, `+${b.colorPts}`];
|
|
||||||
vals.forEach((v, k) => add(scene.add.text(x + cols[k][1], ry, v, {
|
|
||||||
fontFamily: 'Righteous', fontSize: '20px', color: v.startsWith('−') ? '#a7311d' : INK,
|
|
||||||
}).setOrigin(0.5).setDepth(depth + 2)));
|
|
||||||
add(scene.add.text(x + cols[5][1], ry, `${p.score}`, { fontFamily: 'Righteous', fontSize: '30px', color: COBALT }).setOrigin(0.5).setDepth(depth + 2));
|
|
||||||
// Miniature wall.
|
|
||||||
const cs = 13, wx = x + 1010 - (WALL_SIZE * cs) / 2, wy = ry - (WALL_SIZE * cs) / 2;
|
|
||||||
const wg = add(scene.add.graphics().setDepth(depth + 2));
|
|
||||||
wg.fillStyle(0xc6b48c, 1).fillRect(wx - 2, wy - 2, WALL_SIZE * cs + 3, WALL_SIZE * cs + 3);
|
|
||||||
for (let rr = 0; rr < WALL_SIZE; rr++) for (let cc = 0; cc < WALL_SIZE; cc++) {
|
|
||||||
const col = cellColor(p, rr, cc);
|
|
||||||
wg.fillStyle(col ? TILE_HEX[col] : 0xeee4cc, 1).fillRect(wx + cc * cs, wy + rr * cs, cs - 1, cs - 1);
|
|
||||||
}
|
|
||||||
add(scene.add.text(x + 1080, ry, `set ${st.tilesPlaced} · floored ${st.tilesFloored}\nfirst ×${st.firstTaken} · best +${st.bestPlacement}`, {
|
|
||||||
fontFamily: SERIF, fontSize: '13px', color: INK, lineSpacing: 4,
|
|
||||||
}).setOrigin(0, 0.5).setDepth(depth + 2));
|
|
||||||
});
|
|
||||||
|
|
||||||
// ── points by round ──────────────────────────────────────────────────────────
|
|
||||||
const cx0 = x + 110, cy0 = y + 150 + n * rowH + 10, cw = w - 260, ch = chartH - 40;
|
|
||||||
const series = gs.players.map((p) => [0, ...p.stats.roundScores]);
|
|
||||||
const maxV = Math.max(10, ...series.flat());
|
|
||||||
const steps = Math.max(...series.map((s) => s.length)) - 1;
|
|
||||||
const cg = add(scene.add.graphics().setDepth(depth + 1));
|
|
||||||
cg.fillStyle(0xffffff, 0.45).fillRoundedRect(cx0 - 60, cy0 - 10, cw + 120, ch + 50, 8);
|
|
||||||
cg.lineStyle(1, 0x6b5226, 0.35);
|
|
||||||
const gridStep = maxV > 60 ? 20 : 10;
|
|
||||||
for (let v = 0; v <= maxV; v += gridStep) {
|
|
||||||
const yy = cy0 + ch - (v / maxV) * ch;
|
|
||||||
cg.lineBetween(cx0, yy, cx0 + cw, yy);
|
|
||||||
add(scene.add.text(cx0 - 10, yy, `${v}`, { fontFamily: SERIF, fontSize: '11px', color: '#6b5226' }).setOrigin(1, 0.5).setDepth(depth + 2));
|
|
||||||
}
|
|
||||||
const xAt = (k) => cx0 + (steps ? (k / steps) * cw : 0);
|
|
||||||
const lastRound = gs.round;
|
|
||||||
for (let k = 0; k <= steps; k++) {
|
|
||||||
const label = k === 0 ? 'start' : k <= lastRound ? `R${k}` : 'bonus';
|
|
||||||
add(scene.add.text(xAt(k), cy0 + ch + 14, label, { fontFamily: SERIF, fontSize: '12px', fontStyle: 'italic', color: '#6b5226' }).setOrigin(0.5).setDepth(depth + 2));
|
|
||||||
}
|
|
||||||
series.forEach((s, seat) => {
|
|
||||||
const col = SEAT_INK[seat % SEAT_INK.length];
|
|
||||||
cg.lineStyle(seat === 0 ? 4 : 2.5, col, 0.95);
|
|
||||||
cg.beginPath();
|
|
||||||
s.forEach((v, k) => { const px = xAt(k), py = cy0 + ch - (v / maxV) * ch; if (k) cg.lineTo(px, py); else cg.moveTo(px, py); });
|
|
||||||
cg.strokePath();
|
|
||||||
s.forEach((v, k) => cg.fillStyle(col, 1).fillCircle(xAt(k), cy0 + ch - (v / maxV) * ch, seat === 0 ? 4.5 : 3.5));
|
|
||||||
add(scene.add.text(xAt(steps) + 12, cy0 + ch - (s[s.length - 1] / maxV) * ch, gs.players[seat].name, {
|
|
||||||
fontFamily: SERIF, fontSize: '12px', color: hexStr(col),
|
|
||||||
}).setOrigin(0, 0.5).setDepth(depth + 2));
|
|
||||||
});
|
|
||||||
|
|
||||||
// ── buttons ──────────────────────────────────────────────────────────────────
|
|
||||||
const by = y + h - 50;
|
|
||||||
let hidden = false;
|
|
||||||
const panelObjs = objs.slice();
|
|
||||||
const viewBtn = new Button(scene, x + w / 2, by, 'View Table', () => {
|
|
||||||
hidden = !hidden;
|
|
||||||
panelObjs.forEach((o) => o.setVisible?.(!hidden));
|
|
||||||
if (panelObjs[0].input) panelObjs[0].input.enabled = !hidden; // the click blocker
|
|
||||||
viewBtn.setLabel(hidden ? 'Show Results' : 'View Table');
|
|
||||||
viewBtn.setPosition(hidden ? GAME_WIDTH / 2 : x + w / 2, hidden ? 652 : by);
|
|
||||||
if (hidden) onShowPortraits?.(); else onHidePortraits?.();
|
|
||||||
}, { width: 220, height: 48, fontSize: 18, bg: 0x5a3820 }).setDepth(depth + 3);
|
|
||||||
add(viewBtn);
|
|
||||||
add(new Button(scene, x + w / 2 - 260, by, 'Play Again', () => onPlayAgain(), { width: 220, height: 48, fontSize: 19, bg: 0x1d4f8f }).setDepth(depth + 3));
|
|
||||||
add(new Button(scene, x + w / 2 + 260, by, 'Leave', () => onLeave(), { width: 220, height: 48, fontSize: 19, bg: 0x7a2a1a }).setDepth(depth + 3));
|
|
||||||
onHidePortraits?.();
|
|
||||||
|
|
||||||
// Fade in.
|
|
||||||
panelObjs.forEach((o) => { if (o.setAlpha) { const a = o.alpha; o.setAlpha(0); scene.tweens.add({ targets: o, alpha: a, duration: 350 }); } });
|
|
||||||
return { close() { objs.forEach((o) => o.destroy?.()); } };
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,312 +0,0 @@
|
||||||
// AzulHud.js — the workshop's furniture that isn't tiles:
|
|
||||||
// • board headers (name, rolling score, first-player star) + bonus badges
|
|
||||||
// • the tile tracker (bottom-left): where every colour is
|
|
||||||
// • the work-order panel (bottom-centre): whose turn, what to do, the move
|
|
||||||
// preview and up to three dock buttons
|
|
||||||
// • the scoreboard (bottom-right): round, standings, wall variant
|
|
||||||
// • the order book (right): the last few log lines
|
|
||||||
|
|
||||||
import { Button } from '../../ui/Button.js';
|
|
||||||
import { COLORS, TILE_NAME, WALL_SIZE, ROW_BONUS, COLUMN_BONUS, COLOR_BONUS } from './AzulData.js';
|
|
||||||
import { bonusStatus } from './AzulLogic.js';
|
|
||||||
import {
|
|
||||||
TRACKER, ACTION, SCORES, NOTEPAD, DOCK, boardOf, bonusBadgeAt,
|
|
||||||
} from './AzulLayout.js';
|
|
||||||
import { SERIF, DISPLAY, COBALT, INK, SHADOW, tileKey, tileDisplay } from './AzulArt.js';
|
|
||||||
|
|
||||||
const CREAM = '#f6efdc';
|
|
||||||
|
|
||||||
export class AzulHud {
|
|
||||||
constructor(scene, { depth, playerCount, names, tooltip }) {
|
|
||||||
this.scene = scene;
|
|
||||||
this.D = depth;
|
|
||||||
this.n = playerCount;
|
|
||||||
this.names = names;
|
|
||||||
this.tooltip = tooltip;
|
|
||||||
this.shown = Array(playerCount).fill(0); // displayed (rolling) scores
|
|
||||||
this.scoreTweens = [];
|
|
||||||
this.buildPanels();
|
|
||||||
this.buildHeaders();
|
|
||||||
this.buildTracker();
|
|
||||||
this.buildAction();
|
|
||||||
this.buildScores();
|
|
||||||
this.buildNotepad();
|
|
||||||
}
|
|
||||||
|
|
||||||
add(o) { return o; }
|
|
||||||
|
|
||||||
buildPanels() {
|
|
||||||
const s = this.scene;
|
|
||||||
const img = (key, r) => s.add.image(r.x - SHADOW, r.y - SHADOW, key).setOrigin(0).setDepth(this.D.panel);
|
|
||||||
this.trackerPanel = img('azul-panel-tracker', TRACKER);
|
|
||||||
img('azul-panel-action', ACTION);
|
|
||||||
img('azul-panel-scores', SCORES);
|
|
||||||
s.add.image(NOTEPAD.x - SHADOW, NOTEPAD.y - SHADOW, 'azul-notepad').setOrigin(0).setDepth(this.D.panel);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── board headers ───────────────────────────────────────────────────────────
|
|
||||||
buildHeaders() {
|
|
||||||
const s = this.scene;
|
|
||||||
this.headers = [];
|
|
||||||
for (let seat = 0; seat < this.n; seat++) {
|
|
||||||
const { rect, m } = boardOf(seat, this.n);
|
|
||||||
const big = m.size === 'big';
|
|
||||||
const nameX = rect.x + m.pad + (big ? 40 : 30); // clears the hanging portrait
|
|
||||||
const hy = rect.y + (m.headerH - (big ? 8 : 6)) / 2;
|
|
||||||
const name = s.add.text(nameX, hy, this.names[seat] + (seat === 0 ? ' (you)' : ''), {
|
|
||||||
fontFamily: DISPLAY, fontSize: big ? '22px' : '17px', color: CREAM,
|
|
||||||
}).setOrigin(0, 0.5).setDepth(this.D.label);
|
|
||||||
const score = s.add.text(rect.x + rect.w - m.pad - 4, hy, '0', {
|
|
||||||
fontFamily: 'Righteous', fontSize: big ? '28px' : '22px', color: '#ffe08a', stroke: '#0e2442', strokeThickness: 3,
|
|
||||||
}).setOrigin(1, 0.5).setDepth(this.D.label);
|
|
||||||
const star = s.add.text(score.x - (big ? 60 : 46), hy, '①', {
|
|
||||||
fontFamily: SERIF, fontSize: big ? '22px' : '18px', color: '#ffffff',
|
|
||||||
}).setOrigin(1, 0.5).setDepth(this.D.label).setVisible(false);
|
|
||||||
// Active-turn frame (drawn just outside the board).
|
|
||||||
const glow = s.add.graphics().setDepth(this.D.boardGlow);
|
|
||||||
glow.lineStyle(big ? 5 : 4, 0xffd36b, 1).strokeRoundedRect(rect.x - 4, rect.y - 4, rect.w + 8, rect.h + 8, big ? 14 : 11);
|
|
||||||
glow.setAlpha(0);
|
|
||||||
// Bonus badge.
|
|
||||||
const bb = bonusBadgeAt(rect, m);
|
|
||||||
const badge = s.add.text(bb.x + bb.w - 2, bb.y + bb.h / 2, '', {
|
|
||||||
fontFamily: SERIF, fontSize: big ? '14px' : '11px', color: '#1d4f8f', fontStyle: 'bold', align: 'right', lineSpacing: -2,
|
|
||||||
}).setOrigin(1, 0.5).setDepth(this.D.label);
|
|
||||||
const bz = s.add.zone(bb.x + bb.w / 2, bb.y + bb.h / 2, bb.w, bb.h).setInteractive().setDepth(this.D.zone + 1);
|
|
||||||
this.tooltip.attachTo(bz, () => this.bonusTooltip(seat));
|
|
||||||
this.headers.push({ name, score, star, glow, badge, bz, big });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setActive(seat) {
|
|
||||||
this.headers.forEach((h, i) => {
|
|
||||||
const on = i === seat;
|
|
||||||
this.scene.tweens.killTweensOf(h.glow);
|
|
||||||
if (on) {
|
|
||||||
h.glow.setAlpha(1);
|
|
||||||
this.scene.tweens.add({ targets: h.glow, alpha: 0.45, duration: 900, yoyo: true, repeat: -1, ease: 'Sine.easeInOut' });
|
|
||||||
} else h.glow.setAlpha(0);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
setStartPlayer(seat, hasMarker) {
|
|
||||||
this.headers.forEach((h, i) => h.star.setVisible(!!hasMarker && i === seat));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Score text: snap (no animation) or roll from what's shown now.
|
|
||||||
setScore(seat, value, { roll = false, ms = 500 } = {}) {
|
|
||||||
const h = this.headers[seat];
|
|
||||||
this.scoreTweens[seat]?.stop?.();
|
|
||||||
if (!roll) { this.shown[seat] = value; h.score.setText(`${value}`); this.refreshScores(); return; }
|
|
||||||
const from = this.shown[seat];
|
|
||||||
const o = { v: from };
|
|
||||||
this.scoreTweens[seat] = this.scene.tweens.add({
|
|
||||||
targets: o, v: value, duration: ms, ease: 'Cubic.easeOut',
|
|
||||||
onUpdate: () => { this.shown[seat] = Math.round(o.v); h.score.setText(`${this.shown[seat]}`); },
|
|
||||||
onComplete: () => { this.shown[seat] = value; h.score.setText(`${value}`); this.refreshScores(); },
|
|
||||||
});
|
|
||||||
this.scene.tweens.add({ targets: h.score, scale: { from: 1.25, to: 1 }, duration: 380, ease: 'Back.easeOut' });
|
|
||||||
}
|
|
||||||
|
|
||||||
setBonuses(gs, show) {
|
|
||||||
this.gs = gs;
|
|
||||||
this.headers.forEach((h, seat) => {
|
|
||||||
if (!show) { h.badge.setText(''); return; }
|
|
||||||
const b = bonusStatus(gs.players[seat]);
|
|
||||||
const near = b.cols.filter((n) => n === WALL_SIZE - 1).length + Object.values(b.colors).filter((n) => n === WALL_SIZE - 1).length;
|
|
||||||
const txt = b.locked || near ? `+${b.locked}${near ? ` (${near}★)` : ''}` : '';
|
|
||||||
h.badge.setText(txt ? (h.big ? `Bonus ${txt}` : txt) : '');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
bonusTooltip(seat) {
|
|
||||||
const gs = this.gs;
|
|
||||||
if (!gs) return { title: 'Bonuses', lines: [] };
|
|
||||||
const b = bonusStatus(gs.players[seat]);
|
|
||||||
const lines = [];
|
|
||||||
const row = (label, arr, bonus) => {
|
|
||||||
const parts = arr.map((n, i) => `${label[0]}${i + 1}:${n}`).join(' ');
|
|
||||||
return { text: `${label} (+${bonus} each): ${parts}` };
|
|
||||||
};
|
|
||||||
lines.push(row('Rows', b.rows, ROW_BONUS));
|
|
||||||
lines.push(row('Columns', b.cols, COLUMN_BONUS));
|
|
||||||
lines.push({ text: `Colours (+${COLOR_BONUS} each): ${COLORS.map((c) => `${TILE_NAME[c]} ${b.colors[c]}`).join(' · ')}` });
|
|
||||||
lines.push({ text: `Locked in: +${b.locked}. A ★ is a set with 4 of 5 — one tile from a bonus.`, color: '#ffe08a' });
|
|
||||||
return { title: `${this.names[seat]} — end-game bonuses`, lines };
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── tile tracker ────────────────────────────────────────────────────────────
|
|
||||||
buildTracker() {
|
|
||||||
const s = this.scene;
|
|
||||||
const x = TRACKER.x, y = TRACKER.y;
|
|
||||||
this.trk = { objs: [] };
|
|
||||||
const head = s.add.text(x + TRACKER.w / 2, y + 30, 'Tile Tracker', { fontFamily: DISPLAY, fontSize: '20px', color: COBALT }).setOrigin(0.5).setDepth(this.D.label);
|
|
||||||
const cols = [['Bag', 132], ['Lid', 182], ['Table', 232], ['Walls', 280]];
|
|
||||||
const colHeads = cols.map(([t, cx]) => s.add.text(x + cx, y + 62, t, { fontFamily: SERIF, fontSize: '12px', color: '#6b5226', fontStyle: 'italic' }).setOrigin(0.5).setDepth(this.D.label));
|
|
||||||
this.trk.rows = COLORS.map((c, i) => {
|
|
||||||
const ry = y + 96 + i * 50;
|
|
||||||
const icon = s.add.image(x + 46, ry, tileKey(c, false)).setDisplaySize(tileDisplay(32), tileDisplay(32)).setDepth(this.D.label);
|
|
||||||
const name = s.add.text(x + 70, ry, TILE_NAME[c], { fontFamily: SERIF, fontSize: '13px', color: INK }).setOrigin(0, 0.5).setDepth(this.D.label);
|
|
||||||
const nums = cols.map(([, cx]) => s.add.text(x + cx, ry, '0', { fontFamily: 'Righteous', fontSize: '18px', color: INK }).setOrigin(0.5).setDepth(this.D.label));
|
|
||||||
const zone = s.add.zone(x + TRACKER.w / 2, ry, TRACKER.w - 28, 44).setInteractive().setDepth(this.D.zone);
|
|
||||||
this.tooltip.attachTo(zone, () => this.trackerTooltip(c));
|
|
||||||
return { c, icon, name, nums, zone };
|
|
||||||
});
|
|
||||||
this.trk.foot = s.add.text(x + TRACKER.w / 2, y + TRACKER.h - 30, '', { fontFamily: SERIF, fontSize: '12px', fontStyle: 'italic', color: '#6b5226', align: 'center' }).setOrigin(0.5).setDepth(this.D.label);
|
|
||||||
this.trk.hidden = s.add.text(x + TRACKER.w / 2, y + TRACKER.h / 2, 'Tracker off\n(Menu → Tile tracker)', { fontFamily: SERIF, fontSize: '15px', fontStyle: 'italic', color: '#6b5226', align: 'center' }).setOrigin(0.5).setDepth(this.D.label).setVisible(false);
|
|
||||||
this.trk.objs = [head, ...colHeads, ...this.trk.rows.flatMap((r) => [r.icon, r.name, ...r.nums]), this.trk.foot];
|
|
||||||
}
|
|
||||||
|
|
||||||
setTracker(census, visible) {
|
|
||||||
this.census = census;
|
|
||||||
this.trk.objs.forEach((o) => o.setVisible(visible));
|
|
||||||
this.trk.hidden.setVisible(!visible);
|
|
||||||
this.trk.rows.forEach((r) => r.zone.input && (r.zone.input.enabled = visible));
|
|
||||||
if (!visible) return;
|
|
||||||
let unseen = 0;
|
|
||||||
this.trk.rows.forEach((r) => {
|
|
||||||
const k = census[r.c];
|
|
||||||
const vals = [k.bag, k.lid, k.table, k.walls];
|
|
||||||
r.nums.forEach((t, i) => t.setText(`${vals[i]}`));
|
|
||||||
// Bag low → colour the count.
|
|
||||||
r.nums[0].setColor(k.bag <= 2 ? '#a7311d' : INK);
|
|
||||||
unseen += k.bag;
|
|
||||||
});
|
|
||||||
this.trk.foot.setText(`${unseen} in the bag · lid refills it when empty`);
|
|
||||||
}
|
|
||||||
|
|
||||||
trackerTooltip(c) {
|
|
||||||
const k = this.census?.[c];
|
|
||||||
if (!k) return { title: TILE_NAME[c], lines: [] };
|
|
||||||
return {
|
|
||||||
title: `${TILE_NAME[c]} tiles (20)`,
|
|
||||||
lines: [
|
|
||||||
{ text: `In the bag: ${k.bag}` },
|
|
||||||
{ text: `In the lid (discarded): ${k.lid}` },
|
|
||||||
{ text: `On plates / centre: ${k.table}` },
|
|
||||||
{ text: `On pattern lines: ${k.lines}` },
|
|
||||||
{ text: `On floor lines: ${k.floors}` },
|
|
||||||
{ text: `Set on walls: ${k.walls}` },
|
|
||||||
],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── work-order panel ──────────────────────────────────────────────────────────
|
|
||||||
buildAction() {
|
|
||||||
const s = this.scene;
|
|
||||||
const cx = ACTION.x + ACTION.w / 2;
|
|
||||||
this.act = {};
|
|
||||||
this.act.title = s.add.text(cx, ACTION.y + 40, '', { fontFamily: DISPLAY, fontSize: '26px', color: COBALT }).setOrigin(0.5).setDepth(this.D.label);
|
|
||||||
this.act.body = s.add.text(cx, ACTION.y + 100, '', {
|
|
||||||
fontFamily: SERIF, fontSize: '17px', color: INK, align: 'center', lineSpacing: 6, wordWrap: { width: ACTION.w - 70 },
|
|
||||||
}).setOrigin(0.5, 0.5).setDepth(this.D.label);
|
|
||||||
this.act.previewBg = s.add.graphics().setDepth(this.D.label - 1);
|
|
||||||
this.act.preview = s.add.text(cx, ACTION.y + 214, '', {
|
|
||||||
fontFamily: SERIF, fontSize: '16px', color: '#1d3f6e', align: 'center', lineSpacing: 5, wordWrap: { width: ACTION.w - 80 },
|
|
||||||
}).setOrigin(0.5).setDepth(this.D.label);
|
|
||||||
this.dock = DOCK.map((r) => {
|
|
||||||
const b = new Button(s, r.x, r.y, '', () => b._fn?.(), { width: r.w, height: r.h, fontSize: 17, bg: 0x1d4f8f }).setDepth(this.D.label + 2);
|
|
||||||
b.setVisible(false);
|
|
||||||
return b;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
setAction(title, body, tone = 'plain') {
|
|
||||||
this.act.title.setText(title);
|
|
||||||
this.act.title.setColor(tone === 'you' ? COBALT : tone === 'warn' ? '#a7311d' : '#6b5226');
|
|
||||||
this.act.body.setText(body);
|
|
||||||
}
|
|
||||||
|
|
||||||
setPreview(text, tone = 'plain') {
|
|
||||||
const g = this.act.previewBg;
|
|
||||||
g.clear();
|
|
||||||
this.act.preview.setText(text ?? '');
|
|
||||||
if (!text) return;
|
|
||||||
const b = this.act.preview.getBounds();
|
|
||||||
const fill = tone === 'bad' ? 0xf2d2c4 : tone === 'good' ? 0xd8e6d0 : 0xe6ecf4;
|
|
||||||
g.fillStyle(fill, 1).fillRoundedRect(b.x - 16, b.y - 10, b.width + 32, b.height + 20, 8);
|
|
||||||
g.lineStyle(1.5, tone === 'bad' ? 0xa7311d : tone === 'good' ? 0x3c7a3a : 0x1d4f8f, 0.7).strokeRoundedRect(b.x - 16, b.y - 10, b.width + 32, b.height + 20, 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
// buttons: [{ label, fn, bg }] — up to three, left to right.
|
|
||||||
setDock(buttons = []) {
|
|
||||||
this.dock.forEach((b, i) => {
|
|
||||||
const spec = buttons[i];
|
|
||||||
if (!spec) { b.setVisible(false); b.disableInteractive(); b._fn = null; return; }
|
|
||||||
b._fn = spec.fn;
|
|
||||||
b.setLabel(spec.label);
|
|
||||||
b.options.bg = spec.bg ?? 0x1d4f8f;
|
|
||||||
b._drawBg(b.options.bg, 1);
|
|
||||||
b.setVisible(true);
|
|
||||||
b.setEnabled(spec.enabled !== false);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── scoreboard ───────────────────────────────────────────────────────────────
|
|
||||||
buildScores() {
|
|
||||||
const s = this.scene;
|
|
||||||
const cx = SCORES.x + SCORES.w / 2;
|
|
||||||
this.sc = {};
|
|
||||||
this.sc.round = s.add.text(cx, SCORES.y + 38, '', { fontFamily: DISPLAY, fontSize: '26px', color: COBALT }).setOrigin(0.5).setDepth(this.D.label);
|
|
||||||
this.sc.sub = s.add.text(cx, SCORES.y + 70, '', { fontFamily: SERIF, fontSize: '13px', fontStyle: 'italic', color: '#6b5226' }).setOrigin(0.5).setDepth(this.D.label);
|
|
||||||
this.sc.rows = Array.from({ length: this.n }, (_, i) => {
|
|
||||||
const y = SCORES.y + 116 + i * 54;
|
|
||||||
const bg = s.add.graphics().setDepth(this.D.label - 1);
|
|
||||||
const rank = s.add.text(SCORES.x + 40, y, '', { fontFamily: 'Righteous', fontSize: '18px', color: '#6b5226' }).setOrigin(0.5).setDepth(this.D.label);
|
|
||||||
const name = s.add.text(SCORES.x + 62, y - 8, '', { fontFamily: SERIF, fontSize: '17px', color: INK }).setOrigin(0, 0.5).setDepth(this.D.label);
|
|
||||||
const sub = s.add.text(SCORES.x + 62, y + 13, '', { fontFamily: SERIF, fontSize: '12px', fontStyle: 'italic', color: '#6b5226' }).setOrigin(0, 0.5).setDepth(this.D.label);
|
|
||||||
const pts = s.add.text(SCORES.x + SCORES.w - 34, y, '', { fontFamily: 'Righteous', fontSize: '24px', color: COBALT }).setOrigin(1, 0.5).setDepth(this.D.label);
|
|
||||||
return { bg, rank, name, sub, pts, y };
|
|
||||||
});
|
|
||||||
this.sc.foot = s.add.text(cx, SCORES.y + SCORES.h - 30, '', { fontFamily: SERIF, fontSize: '13px', fontStyle: 'italic', color: '#6b5226', align: 'center' }).setOrigin(0.5).setDepth(this.D.label);
|
|
||||||
}
|
|
||||||
|
|
||||||
setRound(gs, { label } = {}) {
|
|
||||||
this.gs = gs;
|
|
||||||
this.sc.round.setText(label ?? (gs.phase === 'gameOver' ? 'Final' : `Round ${gs.round}`));
|
|
||||||
const plates = gs.factories.filter((f) => f.length).length;
|
|
||||||
this.sc.sub.setText(gs.phase === 'offer' ? `${plates} plate${plates === 1 ? '' : 's'} left · ${gs.center.length} in the centre` : gs.phase === 'scoring' ? 'tiling the walls' : '');
|
|
||||||
this.sc.foot.setText(gs.variant === 'free' ? 'Free wall — place tiles anywhere legal' : 'Printed wall');
|
|
||||||
this.refreshScores();
|
|
||||||
}
|
|
||||||
|
|
||||||
refreshScores() {
|
|
||||||
const gs = this.gs;
|
|
||||||
if (!gs) return;
|
|
||||||
const order = gs.players.map((p) => p.seat).sort((a, b) => this.shown[b] - this.shown[a] || a - b);
|
|
||||||
order.forEach((seat, i) => {
|
|
||||||
const r = this.sc.rows[i];
|
|
||||||
const p = gs.players[seat];
|
|
||||||
const b = bonusStatus(p);
|
|
||||||
r.rank.setText(`${i + 1}`);
|
|
||||||
r.name.setText(seat === 0 ? `${p.name} (you)` : p.name);
|
|
||||||
r.sub.setText(`${b.rows.filter((n) => n === WALL_SIZE).length ? 'row done · ' : ''}${b.rows.reduce((a, c) => a + c, 0)} on wall${b.locked ? ` · +${b.locked} locked` : ''}`);
|
|
||||||
r.pts.setText(`${this.shown[seat]}`);
|
|
||||||
r.bg.clear();
|
|
||||||
const cur = gs.phase === 'offer' && gs.current === seat;
|
|
||||||
r.bg.fillStyle(cur ? 0xffe7a8 : seat === 0 ? 0xe6ecf4 : 0xffffff, cur ? 0.9 : 0.45)
|
|
||||||
.fillRoundedRect(SCORES.x + 22, r.y - 24, SCORES.w - 44, 48, 6);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── order book ───────────────────────────────────────────────────────────────
|
|
||||||
buildNotepad() {
|
|
||||||
const s = this.scene;
|
|
||||||
s.add.text(NOTEPAD.x + 20, NOTEPAD.y + 13, 'Order Book', { fontFamily: DISPLAY, fontSize: '15px', color: '#f3dcc0' }).setOrigin(0, 0.5).setDepth(this.D.label);
|
|
||||||
this.np = s.add.text(NOTEPAD.x + 54, NOTEPAD.y + 46, '', {
|
|
||||||
fontFamily: SERIF, fontSize: '14px', fontStyle: 'italic', color: '#1d3f6e', lineSpacing: 10.5, wordWrap: { width: NOTEPAD.w - 74 },
|
|
||||||
fixedWidth: NOTEPAD.w - 74,
|
|
||||||
}).setDepth(this.D.label);
|
|
||||||
const maskG = s.make.graphics({ x: 0, y: 0, add: false });
|
|
||||||
maskG.fillStyle(0xffffff).fillRect(NOTEPAD.x + 6, NOTEPAD.y + 30, NOTEPAD.w - 12, NOTEPAD.h - 34);
|
|
||||||
this.np.setMask(maskG.createGeometryMask());
|
|
||||||
s.events.once('shutdown', () => maskG.destroy());
|
|
||||||
}
|
|
||||||
|
|
||||||
setLog(log) {
|
|
||||||
// Newest at the bottom: show as many recent lines as fit.
|
|
||||||
const lines = log.slice(-12);
|
|
||||||
this.np.setText(lines.join('\n'));
|
|
||||||
const maxH = NOTEPAD.h - 56;
|
|
||||||
while (this.np.height > maxH && lines.length > 1) { lines.shift(); this.np.setText(lines.join('\n')); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,224 +0,0 @@
|
||||||
// AzulLayout.js — every screen rect for the Azul workshop table.
|
|
||||||
// Phaser-free so tools/verifyAzul.js can check on-screen, overlaps and fit.
|
|
||||||
//
|
|
||||||
// ┌────────────── azulejo wainscot · title · Menu / Log / How to Play ─────────────┐
|
|
||||||
// │ music opponent boards (1–3, portraits hang off their left edge) │
|
|
||||||
// │ bag + lid ○ ○ ○ factory plates round the centre tray ○ notepad │
|
|
||||||
// │ ○ [ centre tray ] ○ │
|
|
||||||
// │ tile tracker │ (portrait) YOUR BOARD │ work-order panel │ round + scoreboard │
|
|
||||||
// └────────────────────────────────────────────────────────────────────────────────┘
|
|
||||||
|
|
||||||
import { WALL_SIZE, FLOOR_SIZE, factoryCount } from './AzulData.js';
|
|
||||||
|
|
||||||
export const W = 1920, H = 1080;
|
|
||||||
|
|
||||||
// ── board metrics ──────────────────────────────────────────────────────────────
|
|
||||||
// A board is [pattern lines | gap | wall] over a floor line, below a header.
|
|
||||||
function metrics(m) {
|
|
||||||
const w = m.pad * 2 + WALL_SIZE * m.cell + m.wallGap + WALL_SIZE * m.cell;
|
|
||||||
const floorTop = m.headerH + WALL_SIZE * m.cell + m.floorLabel;
|
|
||||||
const h = floorTop + m.floorCell + m.padB;
|
|
||||||
return { ...m, w, h, floorTop };
|
|
||||||
}
|
|
||||||
export const MINI = metrics({ size: 'mini', tile: 26, cell: 29, wallGap: 16, pad: 10, headerH: 40, floorLabel: 14, floorCell: 24, floorGap: 2, padB: 9 });
|
|
||||||
export const BIG = metrics({ size: 'big', tile: 42, cell: 50, wallGap: 24, pad: 14, headerH: 44, floorLabel: 20, floorCell: 40, floorGap: 4, padB: 12 });
|
|
||||||
|
|
||||||
// ── top band ───────────────────────────────────────────────────────────────────
|
|
||||||
export const WAINSCOT = { x: 0, y: 0, w: W, h: 62 };
|
|
||||||
export const TITLE = { x: 960, y: 31 };
|
|
||||||
export const MENU_BTN = { x: 1530, y: 11, w: 118, h: 40 };
|
|
||||||
export const LOG_BTN = { x: 1656, y: 11, w: 100, h: 40 };
|
|
||||||
export const HELP_BTN = { x: 1764, y: 11, w: 146, h: 40 };
|
|
||||||
export const MUSIC = { right: 300, top: 2 };
|
|
||||||
|
|
||||||
// ── opponents ──────────────────────────────────────────────────────────────────
|
|
||||||
export const OPP_ROW = { top: 74, gap: 112 };
|
|
||||||
export const OPP_PORTRAIT = { r: 44, overlap: 18, dy: 52 };
|
|
||||||
export function oppRect(k, nOpp) {
|
|
||||||
const rowW = nOpp * MINI.w + (nOpp - 1) * OPP_ROW.gap;
|
|
||||||
const x = Math.round(W / 2 - rowW / 2 + k * (MINI.w + OPP_ROW.gap));
|
|
||||||
return { x, y: OPP_ROW.top, w: MINI.w, h: MINI.h };
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── supply: factory plates round the centre tray ──────────────────────────────
|
|
||||||
export const RING = { cx: 960, cy: 492, rx: 360, ry: 130, r: 50, tile: 32, off: 18 };
|
|
||||||
export const TRAY = { cx: 960, cy: 492, w: 360, h: 116, tile: 30, step: 34, pad: 8 };
|
|
||||||
// Plates sit at equal ARC LENGTHS round the ellipse (equal angles would crowd
|
|
||||||
// them at its tight left/right ends), starting from the top.
|
|
||||||
const _ringCache = new Map();
|
|
||||||
export function platePos(i, n) {
|
|
||||||
if (!_ringCache.has(n)) {
|
|
||||||
const N = 2400, P = [];
|
|
||||||
let len = 0, prev = null;
|
|
||||||
for (let k = 0; k <= N; k++) {
|
|
||||||
const a = -Math.PI / 2 + (k / N) * Math.PI * 2;
|
|
||||||
const q = { x: RING.cx + Math.cos(a) * RING.rx, y: RING.cy + Math.sin(a) * RING.ry };
|
|
||||||
if (prev) len += Math.hypot(q.x - prev.x, q.y - prev.y);
|
|
||||||
P.push({ ...q, len });
|
|
||||||
prev = q;
|
|
||||||
}
|
|
||||||
const out = [];
|
|
||||||
let j = 0;
|
|
||||||
for (let k = 0; k < n; k++) {
|
|
||||||
const t = (k / n) * len;
|
|
||||||
while (P[j].len < t) j++;
|
|
||||||
out.push({ x: Math.round(P[j].x * 10) / 10, y: Math.round(P[j].y * 10) / 10 });
|
|
||||||
}
|
|
||||||
_ringCache.set(n, out);
|
|
||||||
}
|
|
||||||
return { ..._ringCache.get(n)[i] };
|
|
||||||
}
|
|
||||||
const PLATE_SLOTS = [[-1, -1], [1, -1], [-1, 1], [1, 1]];
|
|
||||||
export function plateSlot(i, n, slot) {
|
|
||||||
const p = platePos(i, n);
|
|
||||||
const [sx, sy] = PLATE_SLOTS[slot] ?? [0, 0];
|
|
||||||
return { x: p.x + sx * RING.off, y: p.y + sy * RING.off };
|
|
||||||
}
|
|
||||||
export const TRAY_PER_ROW = Math.floor((TRAY.w - TRAY.pad * 2) / TRAY.step);
|
|
||||||
export function centerSlot(idx) {
|
|
||||||
const left = TRAY.cx - (TRAY_PER_ROW * TRAY.step - (TRAY.step - TRAY.tile)) / 2 + TRAY.tile / 2;
|
|
||||||
const top = TRAY.cy - TRAY.h / 2 + TRAY.pad + 15 + TRAY.tile / 2 - 8;
|
|
||||||
return { x: left + (idx % TRAY_PER_ROW) * TRAY.step, y: top + Math.floor(idx / TRAY_PER_ROW) * TRAY.step };
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── bag, lid, notepad ──────────────────────────────────────────────────────────
|
|
||||||
export const SUPPLY = { x: 40, y: 330, w: 480, h: 330 };
|
|
||||||
export const BAG = { x: 190, y: 478, w: 170, h: 190 };
|
|
||||||
export const LID = { x: 400, y: 514, w: 180, h: 118 };
|
|
||||||
export const NOTEPAD = { x: 1392, y: 334, w: 488, h: 322 };
|
|
||||||
|
|
||||||
// ── bottom row ─────────────────────────────────────────────────────────────────
|
|
||||||
export const TRACKER = { x: 20, y: 690, w: 300, h: 372 };
|
|
||||||
export const HUMAN_BOARD = { x: 420, y: 690, w: BIG.w, h: BIG.h };
|
|
||||||
export const HUMAN_PORTRAIT = { r: 50, overlap: 18 };
|
|
||||||
export const ACTION = { x: 1004, y: 690, w: 500, h: 372 };
|
|
||||||
export const SCORES = { x: 1528, y: 690, w: 372, h: 372 };
|
|
||||||
export const POPOVER = { x: 960 - BIG.w / 2, y: 312, w: BIG.w, h: BIG.h };
|
|
||||||
// Dock buttons inside the action panel (centres).
|
|
||||||
export const DOCK_Y = ACTION.y + ACTION.h - 44;
|
|
||||||
export const DOCK = [
|
|
||||||
{ x: ACTION.x + 92, y: DOCK_Y, w: 160, h: 46 },
|
|
||||||
{ x: ACTION.x + ACTION.w / 2, y: DOCK_Y, w: 160, h: 46 },
|
|
||||||
{ x: ACTION.x + ACTION.w - 92, y: DOCK_Y, w: 160, h: 46 },
|
|
||||||
];
|
|
||||||
export const BANNER = { x: 960, y: 640 };
|
|
||||||
|
|
||||||
// ── per-seat board geometry ───────────────────────────────────────────────────
|
|
||||||
// seat 0 is the human (big board, bottom); seats 1..n-1 are the top row.
|
|
||||||
export function boardOf(seat, playerCount) {
|
|
||||||
if (seat === 0) return { rect: { ...HUMAN_BOARD }, m: BIG };
|
|
||||||
return { rect: oppRect(seat - 1, playerCount - 1), m: MINI };
|
|
||||||
}
|
|
||||||
// Cell centres for a board drawn with metrics m at origin (x, y).
|
|
||||||
export function lineCellAt(o, m, row, col) {
|
|
||||||
return { x: o.x + m.pad + col * m.cell + m.cell / 2, y: o.y + m.headerH + row * m.cell + m.cell / 2 };
|
|
||||||
}
|
|
||||||
export function wallCellAt(o, m, row, col) {
|
|
||||||
return { x: o.x + m.pad + WALL_SIZE * m.cell + m.wallGap + col * m.cell + m.cell / 2, y: o.y + m.headerH + row * m.cell + m.cell / 2 };
|
|
||||||
}
|
|
||||||
export function floorCellAt(o, m, k) {
|
|
||||||
return { x: o.x + m.pad + k * (m.floorCell + m.floorGap) + m.floorCell / 2, y: o.y + m.floorTop + m.floorCell / 2 };
|
|
||||||
}
|
|
||||||
// Pattern line `row` fills right-to-left: the k-th tile sits in column 4-k.
|
|
||||||
export function lineTileAt(o, m, row, k) { return lineCellAt(o, m, row, WALL_SIZE - 1 - k); }
|
|
||||||
export function lineZoneAt(o, m, row) {
|
|
||||||
return { x: o.x + m.pad, y: o.y + m.headerH + row * m.cell, w: WALL_SIZE * m.cell, h: m.cell };
|
|
||||||
}
|
|
||||||
export function floorZoneAt(o, m) {
|
|
||||||
return { x: o.x + m.pad - 2, y: o.y + m.floorTop - 2, w: FLOOR_SIZE * (m.floorCell + m.floorGap) + 2, h: m.floorCell + 4 };
|
|
||||||
}
|
|
||||||
export function wallRectAt(o, m) {
|
|
||||||
return { x: o.x + m.pad + WALL_SIZE * m.cell + m.wallGap, y: o.y + m.headerH, w: WALL_SIZE * m.cell, h: WALL_SIZE * m.cell };
|
|
||||||
}
|
|
||||||
export function bonusBadgeAt(o, m) {
|
|
||||||
// Right end of the floor row, under the wall.
|
|
||||||
return { x: o.x + m.w - m.pad - (m.size === 'big' ? 100 : 56), y: o.y + m.floorTop, w: m.size === 'big' ? 100 : 56, h: m.floorCell };
|
|
||||||
}
|
|
||||||
|
|
||||||
export function portraitPos(seat, playerCount) {
|
|
||||||
const { rect } = boardOf(seat, playerCount);
|
|
||||||
if (seat === 0) return { x: rect.x - HUMAN_PORTRAIT.r + HUMAN_PORTRAIT.overlap, y: rect.y + HUMAN_PORTRAIT.r + 8, r: HUMAN_PORTRAIT.r };
|
|
||||||
return { x: rect.x - OPP_PORTRAIT.r + OPP_PORTRAIT.overlap, y: rect.y + OPP_PORTRAIT.dy, r: OPP_PORTRAIT.r };
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── tile poses for the tracker's locations ─────────────────────────────────────
|
|
||||||
// loc: { kind: 'bag'|'lid'|'factory'|'center'|'line'|'wall'|'floor', ... }
|
|
||||||
// Returns { x, y, size, hidden }.
|
|
||||||
export function tilePose(loc, playerCount) {
|
|
||||||
switch (loc.kind) {
|
|
||||||
case 'bag': return { x: BAG.x, y: BAG.y - 20, size: RING.tile, hidden: true };
|
|
||||||
case 'lid': return { x: LID.x, y: LID.y, size: RING.tile * 0.8, hidden: true };
|
|
||||||
case 'factory': { const p = plateSlot(loc.index, factoryCount(playerCount), loc.slot); return { ...p, size: RING.tile }; }
|
|
||||||
case 'center': { const p = centerSlot(loc.slot); return { ...p, size: TRAY.tile }; }
|
|
||||||
default: {
|
|
||||||
const { rect, m } = boardOf(loc.seat, playerCount);
|
|
||||||
if (loc.kind === 'line') return { ...lineTileAt(rect, m, loc.row, loc.slot), size: m.tile };
|
|
||||||
if (loc.kind === 'wall') return { ...wallCellAt(rect, m, loc.row, loc.col), size: m.tile };
|
|
||||||
if (loc.kind === 'floor') return { ...floorCellAt(rect, m, loc.slot), size: m.floorCell - 4 };
|
|
||||||
return { x: W / 2, y: H / 2, size: 30, hidden: true };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── helpers for verify / hit tests ─────────────────────────────────────────────
|
|
||||||
const centred = (c, w, h, name) => ({ name, x: c.x - w / 2, y: c.y - h / 2, w, h });
|
|
||||||
|
|
||||||
export function hudFurniture({ players = 4 } = {}) {
|
|
||||||
const f = [
|
|
||||||
{ name: 'menu', ...MENU_BTN },
|
|
||||||
{ name: 'log', ...LOG_BTN },
|
|
||||||
{ name: 'help', ...HELP_BTN },
|
|
||||||
{ name: 'supply', ...SUPPLY },
|
|
||||||
{ name: 'notepad', ...NOTEPAD },
|
|
||||||
centred({ x: TRAY.cx, y: TRAY.cy }, TRAY.w, TRAY.h, 'tray'),
|
|
||||||
{ name: 'tracker', ...TRACKER },
|
|
||||||
{ name: 'humanBoard', ...HUMAN_BOARD },
|
|
||||||
{ name: 'action', ...ACTION },
|
|
||||||
{ name: 'scores', ...SCORES },
|
|
||||||
];
|
|
||||||
const n = factoryCount(players);
|
|
||||||
for (let i = 0; i < n; i++) f.push(centred(platePos(i, n), RING.r * 2, RING.r * 2, `plate${i}`));
|
|
||||||
for (let k = 0; k < players - 1; k++) {
|
|
||||||
f.push({ name: `opp${k + 1}`, ...oppRect(k, players - 1) });
|
|
||||||
const pp = portraitPos(k + 1, players);
|
|
||||||
f.push({ ...centred(pp, pp.r * 2, pp.r * 2, `oppPortrait${k + 1}`), overlapOk: [`opp${k + 1}`] });
|
|
||||||
}
|
|
||||||
const hp = portraitPos(0, players);
|
|
||||||
f.push({ ...centred(hp, hp.r * 2, hp.r * 2, 'humanPortrait'), overlapOk: ['humanBoard'] });
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Things that live inside a furniture rect (each must sit within its parent).
|
|
||||||
export function furnitureChildren({ players = 4 } = {}) {
|
|
||||||
const kids = [];
|
|
||||||
for (let idx = 0; idx < 28; idx++) kids.push({ parent: 'tray', ...centred(centerSlot(idx), TRAY.tile, TRAY.tile, `center${idx}`) });
|
|
||||||
const n = factoryCount(players);
|
|
||||||
for (let i = 0; i < n; i++) for (let s = 0; s < 4; s++) {
|
|
||||||
kids.push({ parent: `plate${i}`, ...centred(plateSlot(i, n, s), RING.tile, RING.tile, `plate${i}.${s}`) });
|
|
||||||
}
|
|
||||||
for (let seat = 0; seat < players; seat++) {
|
|
||||||
const { rect, m } = boardOf(seat, players);
|
|
||||||
const parent = seat === 0 ? 'humanBoard' : `opp${seat}`;
|
|
||||||
for (let r = 0; r < WALL_SIZE; r++) {
|
|
||||||
kids.push({ parent, ...lineZoneAt(rect, m, r), name: `s${seat}line${r}` });
|
|
||||||
kids.push({ parent, ...centred(wallCellAt(rect, m, r, 4), m.tile, m.tile), name: `s${seat}wall${r}` });
|
|
||||||
}
|
|
||||||
kids.push({ parent, ...floorZoneAt(rect, m), name: `s${seat}floor` });
|
|
||||||
kids.push({ parent, ...bonusBadgeAt(rect, m), name: `s${seat}bonus` });
|
|
||||||
}
|
|
||||||
for (let i = 0; i < DOCK.length; i++) kids.push({ parent: 'action', ...centred(DOCK[i], DOCK[i].w, DOCK[i].h, `dock${i}`) });
|
|
||||||
kids.push({ parent: 'supply', ...centred(BAG, BAG.w, BAG.h, 'bag') });
|
|
||||||
kids.push({ parent: 'supply', ...centred(LID, LID.w, LID.h, 'lid') });
|
|
||||||
return kids;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const onScreen = (r) => r.x >= 0 && r.y >= 0 && r.x + r.w <= W && r.y + r.h <= H;
|
|
||||||
export const rectsOverlap = (a, b) => a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h;
|
|
||||||
export const inside = (k, p) => k.x >= p.x - 0.5 && k.y >= p.y - 0.5 && k.x + k.w <= p.x + p.w + 0.5 && k.y + k.h <= p.y + p.h + 0.5;
|
|
||||||
export const contains = (r, x, y) => x >= r.x && x <= r.x + r.w && y >= r.y && y <= r.y + r.h;
|
|
||||||
// Circle-vs-rect overlap (plates are discs).
|
|
||||||
export function circleRectOverlap(cx, cy, r, rect) {
|
|
||||||
const nx = Math.max(rect.x, Math.min(cx, rect.x + rect.w));
|
|
||||||
const ny = Math.max(rect.y, Math.min(cy, rect.y + rect.h));
|
|
||||||
return (cx - nx) ** 2 + (cy - ny) ** 2 < r * r;
|
|
||||||
}
|
|
||||||
|
|
@ -9,22 +9,14 @@
|
||||||
// ends; the scene (or AI loop) calls resolveRound() to tile the
|
// ends; the scene (or AI loop) calls resolveRound() to tile the
|
||||||
// walls, score, apply floor penalties, then either deal a new
|
// walls, score, apply floor penalties, then either deal a new
|
||||||
// round or finish the game.
|
// round or finish the game.
|
||||||
//
|
|
||||||
// Two wall variants:
|
|
||||||
// 'standard' — the printed, coloured wall: each colour has one fixed cell per row.
|
|
||||||
// 'free' — the grey (blank) wall: a completed line's tile goes in ANY empty
|
|
||||||
// cell of its row, but a colour may appear only once per row and
|
|
||||||
// once per column. A line whose tile has no legal cell is dumped
|
|
||||||
// onto the floor. resolveRound(state, choices) takes the columns.
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
COLORS, WALL_SIZE, TILES_PER_COLOR, TILES_PER_FACTORY,
|
COLORS, WALL_SIZE, TILES_PER_COLOR, TILES_PER_FACTORY,
|
||||||
FLOOR_PENALTIES, FLOOR_SIZE, ROW_BONUS, COLUMN_BONUS, COLOR_BONUS,
|
FLOOR_PENALTIES, FLOOR_SIZE, ROW_BONUS, COLUMN_BONUS, COLOR_BONUS,
|
||||||
factoryCount, lineCapacity, wallColumnFor, wallColor,
|
factoryCount, lineCapacity, wallColumnFor,
|
||||||
} from './AzulData.js';
|
} from './AzulData.js';
|
||||||
|
|
||||||
const clone = (s) => JSON.parse(JSON.stringify(s));
|
const clone = (s) => JSON.parse(JSON.stringify(s));
|
||||||
export const VARIANTS = ['standard', 'free'];
|
|
||||||
|
|
||||||
// ── seeded RNG (mulberry32) stored on the state ──────────────────────────────
|
// ── seeded RNG (mulberry32) stored on the state ──────────────────────────────
|
||||||
function nextRand(s) {
|
function nextRand(s) {
|
||||||
|
|
@ -44,23 +36,6 @@ function emptyLines() {
|
||||||
function emptyWall() {
|
function emptyWall() {
|
||||||
return Array.from({ length: WALL_SIZE }, () => Array(WALL_SIZE).fill(false));
|
return Array.from({ length: WALL_SIZE }, () => Array(WALL_SIZE).fill(false));
|
||||||
}
|
}
|
||||||
function emptyWallColors() {
|
|
||||||
return Array.from({ length: WALL_SIZE }, () => Array(WALL_SIZE).fill(null));
|
|
||||||
}
|
|
||||||
function emptyStats() {
|
|
||||||
return {
|
|
||||||
placementPts: 0, // points from wall-tiling
|
|
||||||
floorLost: 0, // points actually lost to the floor (after the ≥0 clamp)
|
|
||||||
bonusPts: 0, // end-game row/column/colour bonuses
|
|
||||||
tilesPlaced: 0, // tiles set on the wall
|
|
||||||
tilesFloored: 0, // coloured tiles that landed on the floor line
|
|
||||||
firstTaken: 0, // times this player took the first-player marker
|
|
||||||
bestPlacement: 0, // best single wall placement
|
|
||||||
takes: 0, // drafting turns
|
|
||||||
biggestTake: 0, // most tiles taken in one turn
|
|
||||||
roundScores: [], // score after each round's tiling (then the final total)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── bag / lid drawing ────────────────────────────────────────────────────────
|
// ── bag / lid drawing ────────────────────────────────────────────────────────
|
||||||
function bagTotal(s) { return COLORS.reduce((n, c) => n + s.bag[c], 0); }
|
function bagTotal(s) { return COLORS.reduce((n, c) => n + s.bag[c], 0); }
|
||||||
|
|
@ -70,9 +45,7 @@ function bagTotal(s) { return COLORS.reduce((n, c) => n + s.bag[c], 0); }
|
||||||
function drawTile(s) {
|
function drawTile(s) {
|
||||||
let total = bagTotal(s);
|
let total = bagTotal(s);
|
||||||
if (total === 0) {
|
if (total === 0) {
|
||||||
let moved = 0;
|
for (const c of COLORS) { s.bag[c] += s.lid[c]; s.lid[c] = 0; }
|
||||||
for (const c of COLORS) { moved += s.lid[c]; s.bag[c] += s.lid[c]; s.lid[c] = 0; }
|
|
||||||
if (moved > 0 && s.lastDeal) s.lastDeal.refilled = true;
|
|
||||||
total = bagTotal(s);
|
total = bagTotal(s);
|
||||||
if (total === 0) return null;
|
if (total === 0) return null;
|
||||||
}
|
}
|
||||||
|
|
@ -88,29 +61,25 @@ function drawTile(s) {
|
||||||
// player marker. Mutates `s` in place (callers already cloned).
|
// player marker. Mutates `s` in place (callers already cloned).
|
||||||
function dealFactories(s) {
|
function dealFactories(s) {
|
||||||
const n = factoryCount(s.playerCount);
|
const n = factoryCount(s.playerCount);
|
||||||
s.lastDeal = { round: s.round, refilled: false, short: false };
|
|
||||||
s.factories = [];
|
s.factories = [];
|
||||||
for (let i = 0; i < n; i++) {
|
for (let i = 0; i < n; i++) {
|
||||||
const f = [];
|
const f = [];
|
||||||
for (let t = 0; t < TILES_PER_FACTORY; t++) {
|
for (let t = 0; t < TILES_PER_FACTORY; t++) {
|
||||||
const tile = drawTile(s);
|
const tile = drawTile(s);
|
||||||
if (tile) f.push(tile);
|
if (tile) f.push(tile);
|
||||||
else s.lastDeal.short = true;
|
|
||||||
}
|
}
|
||||||
s.factories.push(f);
|
s.factories.push(f);
|
||||||
}
|
}
|
||||||
s.center = [];
|
s.center = [];
|
||||||
s.centerHasFirst = true;
|
s.centerHasFirst = true;
|
||||||
s.log.push(`— Round ${s.round} —`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── construction ─────────────────────────────────────────────────────────────
|
// ── construction ─────────────────────────────────────────────────────────────
|
||||||
export function createInitialState({ playerCount = 4, names = [], seed, variant = 'standard' } = {}) {
|
export function createInitialState({ playerCount = 4, names = [], seed } = {}) {
|
||||||
const pc = Math.max(2, Math.min(4, playerCount));
|
const pc = Math.max(2, Math.min(4, playerCount));
|
||||||
const s = {
|
const s = {
|
||||||
seed: (seed ?? Math.floor(Math.random() * 1e9)) >>> 0,
|
seed: (seed ?? Math.floor(Math.random() * 1e9)) >>> 0,
|
||||||
rngState: 0,
|
rngState: 0,
|
||||||
variant: VARIANTS.includes(variant) ? variant : 'standard',
|
|
||||||
playerCount: pc,
|
playerCount: pc,
|
||||||
bag: emptyCounts(),
|
bag: emptyCounts(),
|
||||||
lid: emptyCounts(),
|
lid: emptyCounts(),
|
||||||
|
|
@ -122,10 +91,7 @@ export function createInitialState({ playerCount = 4, names = [], seed, variant
|
||||||
startPlayer: 0,
|
startPlayer: 0,
|
||||||
phase: 'offer', // offer | scoring | gameOver
|
phase: 'offer', // offer | scoring | gameOver
|
||||||
round: 1,
|
round: 1,
|
||||||
turn: 0, // drafting turns taken this game
|
|
||||||
roundSummary: null, // per-seat tiling report for the scene to animate
|
roundSummary: null, // per-seat tiling report for the scene to animate
|
||||||
lastMove: null, // what the last applyMove did (for the scene / AI reactions)
|
|
||||||
lastDeal: null,
|
|
||||||
gameEnded: false,
|
gameEnded: false,
|
||||||
log: [],
|
log: [],
|
||||||
};
|
};
|
||||||
|
|
@ -138,10 +104,8 @@ export function createInitialState({ playerCount = 4, names = [], seed, variant
|
||||||
name: names[seat] ?? (seat === 0 ? 'You' : `Player ${seat}`),
|
name: names[seat] ?? (seat === 0 ? 'You' : `Player ${seat}`),
|
||||||
lines: emptyLines(),
|
lines: emptyLines(),
|
||||||
wall: emptyWall(),
|
wall: emptyWall(),
|
||||||
wallColors: emptyWallColors(),
|
|
||||||
floor: [], // entries are colour strings or the literal 'first'
|
floor: [], // entries are colour strings or the literal 'first'
|
||||||
score: 0,
|
score: 0,
|
||||||
stats: emptyStats(),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -153,66 +117,28 @@ export function createInitialState({ playerCount = 4, names = [], seed, variant
|
||||||
|
|
||||||
// ── queries ──────────────────────────────────────────────────────────────────
|
// ── queries ──────────────────────────────────────────────────────────────────
|
||||||
export function currentPlayer(state) { return state.players[state.current]; }
|
export function currentPlayer(state) { return state.players[state.current]; }
|
||||||
export function isFreeWall(state) { return state.variant === 'free'; }
|
|
||||||
|
|
||||||
// Colour sitting on (row, col) of a player's wall, or null.
|
// Can `color` legally go on pattern line `i` for this player?
|
||||||
export function cellColor(player, row, col) {
|
export function lineAccepts(player, i, color) {
|
||||||
if (!player.wall[row][col]) return null;
|
|
||||||
return player.wallColors?.[row]?.[col] ?? wallColor(row, col);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Does this player's wall row already hold `color`?
|
|
||||||
export function rowHasColor(player, row, color) {
|
|
||||||
for (let c = 0; c < WALL_SIZE; c++) if (cellColor(player, row, c) === color) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
function colHasColor(player, col, color) {
|
|
||||||
for (let r = 0; r < WALL_SIZE; r++) if (cellColor(player, r, col) === color) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Can `color` legally go on pattern line `i` for this player? `free` selects
|
|
||||||
// the grey-wall rule (colour not yet in the wall row; any column decided later).
|
|
||||||
export function lineAccepts(player, i, color, free = false) {
|
|
||||||
const line = player.lines[i];
|
const line = player.lines[i];
|
||||||
if (line.count >= lineCapacity(i)) return false; // already full
|
if (line.count >= lineCapacity(i)) return false; // already full
|
||||||
if (line.color !== null && line.color !== color) return false;
|
if (line.color !== null && line.color !== color) return false;
|
||||||
if (free) return !rowHasColor(player, i, color);
|
|
||||||
// The wall cell this line feeds must still be empty.
|
// The wall cell this line feeds must still be empty.
|
||||||
if (player.wall[i][wallColumnFor(i, color)]) return false;
|
if (player.wall[i][wallColumnFor(i, color)]) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Columns a tile of `color` may occupy in `row` (free wall). Standard → [fixed].
|
|
||||||
export function wallOptions(player, row, color, free = false) {
|
|
||||||
if (!free) {
|
|
||||||
const col = wallColumnFor(row, color);
|
|
||||||
return player.wall[row][col] ? [] : [col];
|
|
||||||
}
|
|
||||||
if (rowHasColor(player, row, color)) return [];
|
|
||||||
const out = [];
|
|
||||||
for (let c = 0; c < WALL_SIZE; c++) {
|
|
||||||
if (!player.wall[row][c] && !colHasColor(player, c, color)) out.push(c);
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Distinct colours available from a source array of tile colours.
|
// Distinct colours available from a source array of tile colours.
|
||||||
function coloursIn(tiles) {
|
function coloursIn(tiles) {
|
||||||
return COLORS.filter((c) => tiles.includes(c));
|
return COLORS.filter((c) => tiles.includes(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sourceTiles(state, source) {
|
|
||||||
return source.type === 'factory' ? state.factories[source.index] : state.center;
|
|
||||||
}
|
|
||||||
|
|
||||||
// All legal moves for the current player during the offer phase.
|
// All legal moves for the current player during the offer phase.
|
||||||
// A move = { source: {type:'factory', index} | {type:'center'}, color, line }
|
// A move = { source: {type:'factory', index} | {type:'center'}, color, line }
|
||||||
// where `line` is a pattern-line index 0..4 or the string 'floor'.
|
// where `line` is a pattern-line index 0..4 or the string 'floor'.
|
||||||
export function legalMoves(state) {
|
export function legalMoves(state) {
|
||||||
if (state.phase !== 'offer') return [];
|
if (state.phase !== 'offer') return [];
|
||||||
const p = currentPlayer(state);
|
const p = currentPlayer(state);
|
||||||
const free = isFreeWall(state);
|
|
||||||
const moves = [];
|
const moves = [];
|
||||||
|
|
||||||
const sources = state.factories.map((f, index) => ({ tiles: f, source: { type: 'factory', index } }));
|
const sources = state.factories.map((f, index) => ({ tiles: f, source: { type: 'factory', index } }));
|
||||||
|
|
@ -222,7 +148,7 @@ export function legalMoves(state) {
|
||||||
for (const color of coloursIn(tiles)) {
|
for (const color of coloursIn(tiles)) {
|
||||||
// Each pattern line that can accept the colour, plus the floor (always ok).
|
// Each pattern line that can accept the colour, plus the floor (always ok).
|
||||||
for (let i = 0; i < WALL_SIZE; i++) {
|
for (let i = 0; i < WALL_SIZE; i++) {
|
||||||
if (lineAccepts(p, i, color, free)) moves.push({ source, color, line: i });
|
if (lineAccepts(p, i, color)) moves.push({ source, color, line: i });
|
||||||
}
|
}
|
||||||
moves.push({ source, color, line: 'floor' });
|
moves.push({ source, color, line: 'floor' });
|
||||||
}
|
}
|
||||||
|
|
@ -230,11 +156,6 @@ export function legalMoves(state) {
|
||||||
return moves;
|
return moves;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isLegalMove(state, move) {
|
|
||||||
return legalMoves(state).some((m) => m.color === move.color && m.line === move.line
|
|
||||||
&& m.source.type === move.source.type && (m.source.type === 'center' || m.source.index === move.source.index));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── floor handling ───────────────────────────────────────────────────────────
|
// ── floor handling ───────────────────────────────────────────────────────────
|
||||||
// Add `n` tiles of `color` to a player's floor; overflow past 7 slots → lid.
|
// Add `n` tiles of `color` to a player's floor; overflow past 7 slots → lid.
|
||||||
function addToFloor(s, p, color, n) {
|
function addToFloor(s, p, color, n) {
|
||||||
|
|
@ -244,16 +165,6 @@ function addToFloor(s, p, color, n) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function floorPenaltyFor(len) {
|
|
||||||
let pen = 0;
|
|
||||||
for (let k = 0; k < len && k < FLOOR_SIZE; k++) pen += FLOOR_PENALTIES[k];
|
|
||||||
return pen;
|
|
||||||
}
|
|
||||||
|
|
||||||
function sourceLabel(source) {
|
|
||||||
return source.type === 'center' ? 'the centre' : `plate ${source.index + 1}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── apply an offer move ──────────────────────────────────────────────────────
|
// ── apply an offer move ──────────────────────────────────────────────────────
|
||||||
export function applyMove(state, move) {
|
export function applyMove(state, move) {
|
||||||
const s = clone(state);
|
const s = clone(state);
|
||||||
|
|
@ -262,53 +173,36 @@ export function applyMove(state, move) {
|
||||||
const { source, color } = move;
|
const { source, color } = move;
|
||||||
|
|
||||||
// 1. Gather the chosen colour from the source; scatter the rest as needed.
|
// 1. Gather the chosen colour from the source; scatter the rest as needed.
|
||||||
let taken = 0, tookFirst = false;
|
let taken = 0;
|
||||||
const leftovers = [];
|
|
||||||
if (source.type === 'factory') {
|
if (source.type === 'factory') {
|
||||||
const f = s.factories[source.index];
|
const f = s.factories[source.index];
|
||||||
taken = f.filter((t) => t === color).length;
|
taken = f.filter((t) => t === color).length;
|
||||||
for (const t of f) if (t !== color) { s.center.push(t); leftovers.push(t); } // leftovers → centre
|
for (const t of f) if (t !== color) s.center.push(t); // leftovers → centre
|
||||||
s.factories[source.index] = [];
|
s.factories[source.index] = [];
|
||||||
} else {
|
} else {
|
||||||
taken = s.center.filter((t) => t === color).length;
|
taken = s.center.filter((t) => t === color).length;
|
||||||
s.center = s.center.filter((t) => t !== color);
|
s.center = s.center.filter((t) => t !== color);
|
||||||
if (s.centerHasFirst) {
|
if (s.centerHasFirst) {
|
||||||
s.centerHasFirst = false;
|
s.centerHasFirst = false;
|
||||||
tookFirst = true;
|
|
||||||
s.startPlayer = s.current; // takes the 1st-player marker
|
s.startPlayer = s.current; // takes the 1st-player marker
|
||||||
if (p.floor.length < FLOOR_SIZE) p.floor.push('first');
|
if (p.floor.length < FLOOR_SIZE) p.floor.push('first');
|
||||||
p.stats.firstTaken++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Place the taken tiles on the chosen destination.
|
// 2. Place the taken tiles on the chosen destination.
|
||||||
let placed = 0;
|
if (move.line === 'floor') {
|
||||||
if (move.line !== 'floor') {
|
addToFloor(s, p, color, taken);
|
||||||
|
} else {
|
||||||
const i = move.line;
|
const i = move.line;
|
||||||
const line = p.lines[i];
|
const line = p.lines[i];
|
||||||
line.color = color;
|
line.color = color;
|
||||||
const space = lineCapacity(i) - line.count;
|
const space = lineCapacity(i) - line.count;
|
||||||
placed = Math.min(space, taken);
|
const placed = Math.min(space, taken);
|
||||||
line.count += placed;
|
line.count += placed;
|
||||||
|
addToFloor(s, p, color, taken - placed); // overflow → floor
|
||||||
}
|
}
|
||||||
const overflow = taken - placed;
|
|
||||||
addToFloor(s, p, color, overflow);
|
|
||||||
p.stats.takes++;
|
|
||||||
p.stats.tilesFloored += overflow;
|
|
||||||
p.stats.biggestTake = Math.max(p.stats.biggestTake, taken);
|
|
||||||
|
|
||||||
const dest = move.line === 'floor' ? 'the floor' : `line ${move.line + 1}`;
|
s.log.push(`${p.name} takes ${taken} ${color}.`);
|
||||||
const extras = [];
|
|
||||||
if (move.line !== 'floor' && overflow > 0) extras.push(`${overflow} to the floor`);
|
|
||||||
if (tookFirst) extras.push('takes the first-player marker');
|
|
||||||
s.log.push(`${p.name} takes ${taken} ${color} from ${sourceLabel(source)} → ${dest}${extras.length ? ` (${extras.join(', ')})` : ''}.`);
|
|
||||||
|
|
||||||
s.lastMove = {
|
|
||||||
seat: p.seat, source: { ...source }, color, line: move.line,
|
|
||||||
taken, placed, overflow, tookFirst, leftovers,
|
|
||||||
filled: move.line !== 'floor' && p.lines[move.line].count === lineCapacity(move.line),
|
|
||||||
};
|
|
||||||
s.turn++;
|
|
||||||
|
|
||||||
// 3. Advance the turn; end the offer phase when the table is empty.
|
// 3. Advance the turn; end the offer phase when the table is empty.
|
||||||
s.current = (s.current + 1) % s.playerCount;
|
s.current = (s.current + 1) % s.playerCount;
|
||||||
|
|
@ -333,137 +227,50 @@ export function scorePlacement(wall, row, col) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The cells a placement at (row, col) scores along (for highlighting): the
|
|
||||||
// horizontal run and the vertical run through it (each only if longer than 1).
|
|
||||||
export function placementRun(wall, row, col) {
|
|
||||||
const h = [[row, col]], v = [];
|
|
||||||
for (let c = col - 1; c >= 0 && wall[row][c]; c--) h.push([row, c]);
|
|
||||||
for (let c = col + 1; c < WALL_SIZE && wall[row][c]; c++) h.push([row, c]);
|
|
||||||
for (let r = row - 1; r >= 0 && wall[r][col]; r--) v.push([r, col]);
|
|
||||||
for (let r = row + 1; r < WALL_SIZE && wall[r][col]; r++) v.push([r, col]);
|
|
||||||
const cells = h.length > 1 ? h.slice() : [[row, col]];
|
|
||||||
if (v.length) cells.push(...v);
|
|
||||||
return { cells, horizontal: h.length > 1 ? h.length : 0, vertical: v.length ? v.length + 1 : 0 };
|
|
||||||
}
|
|
||||||
|
|
||||||
function wallRowComplete(wall, row) { return wall[row].every(Boolean); }
|
function wallRowComplete(wall, row) { return wall[row].every(Boolean); }
|
||||||
function colorCount(player, color) {
|
function wallColumnComplete(wall, col) { return wall.every((r) => r[col]); }
|
||||||
let n = 0;
|
function colorComplete(wall, color) {
|
||||||
for (let r = 0; r < WALL_SIZE; r++) for (let c = 0; c < WALL_SIZE; c++) if (cellColor(player, r, c) === color) n++;
|
for (let row = 0; row < WALL_SIZE; row++) if (!wall[row][wallColumnFor(row, color)]) return false;
|
||||||
return n;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
// Bonus status of a wall: how full each row/column/colour is, and the bonus
|
|
||||||
// already locked in (wall tiles never leave, so completed sets are certain).
|
|
||||||
export function bonusStatus(player) {
|
|
||||||
const rows = [], cols = [], colors = {};
|
|
||||||
for (let r = 0; r < WALL_SIZE; r++) rows.push(player.wall[r].filter(Boolean).length);
|
|
||||||
for (let c = 0; c < WALL_SIZE; c++) { let n = 0; for (let r = 0; r < WALL_SIZE; r++) if (player.wall[r][c]) n++; cols.push(n); }
|
|
||||||
for (const color of COLORS) colors[color] = colorCount(player, color);
|
|
||||||
const rowsDone = rows.map((n, i) => (n === WALL_SIZE ? i : -1)).filter((i) => i >= 0);
|
|
||||||
const colsDone = cols.map((n, i) => (n === WALL_SIZE ? i : -1)).filter((i) => i >= 0);
|
|
||||||
const colorsDone = COLORS.filter((c) => colors[c] === WALL_SIZE);
|
|
||||||
const locked = rowsDone.length * ROW_BONUS + colsDone.length * COLUMN_BONUS + colorsDone.length * COLOR_BONUS;
|
|
||||||
return { rows, cols, colors, rowsDone, colsDone, colorsDone, locked };
|
|
||||||
}
|
|
||||||
|
|
||||||
// End-of-game bonus breakdown for one player.
|
|
||||||
export function endBonuses(player) {
|
|
||||||
const b = bonusStatus(player);
|
|
||||||
return {
|
|
||||||
rows: b.rowsDone, cols: b.colsDone, colors: b.colorsDone,
|
|
||||||
rowPts: b.rowsDone.length * ROW_BONUS,
|
|
||||||
colPts: b.colsDone.length * COLUMN_BONUS,
|
|
||||||
colorPts: b.colorsDone.length * COLOR_BONUS,
|
|
||||||
total: b.locked,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Free wall: the column a player would pick by default — most points, then the
|
|
||||||
// column already holding the most tiles (towards the +7), then leftmost.
|
|
||||||
export function defaultWallColumn(player, row, color, options) {
|
|
||||||
let best = null, bestKey = -Infinity;
|
|
||||||
for (const c of options) {
|
|
||||||
player.wall[row][c] = true;
|
|
||||||
const pts = scorePlacement(player.wall, row, c);
|
|
||||||
player.wall[row][c] = false;
|
|
||||||
let colN = 0; for (let r = 0; r < WALL_SIZE; r++) if (player.wall[r][c]) colN++;
|
|
||||||
const key = pts * 100 + colN * 10 + (WALL_SIZE - c);
|
|
||||||
if (key > bestKey) { bestKey = key; best = c; }
|
|
||||||
}
|
|
||||||
void color;
|
|
||||||
return best;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resolve the scoring phase: tile every completed pattern line, score it, apply
|
// Resolve the scoring phase: tile every completed pattern line, score it, apply
|
||||||
// floor penalties, clear floors, then either deal the next round or finish the
|
// floor penalties, clear floors, then either deal the next round or finish the
|
||||||
// game (with end-of-game bonuses). Returns a fresh state carrying `roundSummary`
|
// game (with end-of-game bonuses). Returns a fresh state carrying `roundSummary`
|
||||||
// (one entry per seat) for the scene to animate.
|
// (one entry per seat) for the scene to animate.
|
||||||
// choices (free wall only): { [seat]: { [row]: col } } — missing / illegal
|
export function resolveRound(state) {
|
||||||
// entries fall back to defaultWallColumn.
|
|
||||||
export function resolveRound(state, choices = null) {
|
|
||||||
const s = clone(state);
|
const s = clone(state);
|
||||||
if (s.phase !== 'scoring') return s;
|
if (s.phase !== 'scoring') return s;
|
||||||
const free = isFreeWall(s);
|
|
||||||
|
|
||||||
const summary = s.players.map((p) => {
|
const summary = s.players.map((p) => {
|
||||||
const entry = {
|
const entry = { seat: p.seat, placements: [], floorPenalty: 0, floorTiles: p.floor.slice(), gained: 0 };
|
||||||
seat: p.seat, placements: [], dumped: [], floorPenalty: 0, floorLost: 0,
|
|
||||||
floorTiles: null, gained: 0, scoreBefore: p.score,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Tile completed lines top-to-bottom; score against the wall as it grows.
|
// Tile completed lines top-to-bottom; score against the wall as it grows.
|
||||||
for (let i = 0; i < WALL_SIZE; i++) {
|
for (let i = 0; i < WALL_SIZE; i++) {
|
||||||
const line = p.lines[i];
|
const line = p.lines[i];
|
||||||
if (line.count !== lineCapacity(i)) continue;
|
if (line.count === lineCapacity(i)) {
|
||||||
const opts = wallOptions(p, i, line.color, free);
|
const col = wallColumnFor(i, line.color);
|
||||||
if (opts.length === 0) {
|
|
||||||
// Free wall only: nowhere to put it — the whole line goes to the floor.
|
|
||||||
entry.dumped.push({ row: i, color: line.color, count: line.count });
|
|
||||||
addToFloor(s, p, line.color, line.count);
|
|
||||||
p.stats.tilesFloored += line.count;
|
|
||||||
p.lines[i] = { color: null, count: 0 };
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let col = opts[0];
|
|
||||||
if (free) {
|
|
||||||
const want = choices?.[p.seat]?.[i];
|
|
||||||
col = opts.includes(want) ? want : defaultWallColumn(p, i, line.color, opts);
|
|
||||||
}
|
|
||||||
p.wall[i][col] = true;
|
p.wall[i][col] = true;
|
||||||
p.wallColors[i][col] = line.color;
|
|
||||||
const pts = scorePlacement(p.wall, i, col);
|
const pts = scorePlacement(p.wall, i, col);
|
||||||
const run = placementRun(p.wall, i, col);
|
|
||||||
p.score += pts;
|
p.score += pts;
|
||||||
entry.gained += pts;
|
entry.gained += pts;
|
||||||
entry.placements.push({ row: i, col, color: line.color, points: pts, run: run.cells });
|
entry.placements.push({ row: i, col, color: line.color, points: pts });
|
||||||
p.stats.placementPts += pts;
|
|
||||||
p.stats.tilesPlaced++;
|
|
||||||
p.stats.bestPlacement = Math.max(p.stats.bestPlacement, pts);
|
|
||||||
// Surplus tiles from the line go to the lid; the line resets.
|
// Surplus tiles from the line go to the lid; the line resets.
|
||||||
s.lid[line.color] += line.count - 1;
|
s.lid[line.color] += line.count - 1;
|
||||||
p.lines[i] = { color: null, count: 0 };
|
p.lines[i] = { color: null, count: 0 };
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Floor penalties (clamped so a score never drops below zero).
|
// Floor penalties (clamped so a score never drops below zero).
|
||||||
entry.floorTiles = p.floor.slice();
|
let penalty = 0;
|
||||||
const penalty = floorPenaltyFor(p.floor.length);
|
for (let k = 0; k < p.floor.length && k < FLOOR_SIZE; k++) penalty += FLOOR_PENALTIES[k];
|
||||||
entry.floorPenalty = penalty;
|
entry.floorPenalty = penalty;
|
||||||
const before = p.score;
|
|
||||||
p.score = Math.max(0, p.score + penalty);
|
p.score = Math.max(0, p.score + penalty);
|
||||||
entry.floorLost = before - p.score;
|
|
||||||
p.stats.floorLost += entry.floorLost;
|
|
||||||
|
|
||||||
// Clear the floor; coloured tiles go to the lid, the marker just leaves.
|
// Clear the floor; coloured tiles go to the lid, the marker just leaves.
|
||||||
for (const t of p.floor) if (t !== 'first') s.lid[t]++;
|
for (const t of p.floor) if (t !== 'first') s.lid[t]++;
|
||||||
p.floor = [];
|
p.floor = [];
|
||||||
entry.scoreAfter = p.score;
|
|
||||||
p.stats.roundScores.push(p.score);
|
|
||||||
|
|
||||||
const bits = entry.placements.map((pl) => `+${pl.points}`);
|
|
||||||
s.log.push(`${p.name} tiles ${entry.placements.length} line${entry.placements.length === 1 ? '' : 's'}`
|
|
||||||
+ `${bits.length ? ` (${bits.join(' ')})` : ''}${entry.floorLost ? `, floor −${entry.floorLost}` : ''}`
|
|
||||||
+ `${entry.dumped.length ? `, ${entry.dumped.length} line${entry.dumped.length === 1 ? '' : 's'} dumped` : ''} → ${p.score}.`);
|
|
||||||
return entry;
|
return entry;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -477,17 +284,14 @@ export function resolveRound(state, choices = null) {
|
||||||
|
|
||||||
if (ended) {
|
if (ended) {
|
||||||
for (const p of s.players) {
|
for (const p of s.players) {
|
||||||
const b = endBonuses(p);
|
let bonus = 0;
|
||||||
p.score += b.total;
|
for (let row = 0; row < WALL_SIZE; row++) if (wallRowComplete(p.wall, row)) bonus += ROW_BONUS;
|
||||||
p.stats.bonusPts = b.total;
|
for (let col = 0; col < WALL_SIZE; col++) if (wallColumnComplete(p.wall, col)) bonus += COLUMN_BONUS;
|
||||||
p.stats.roundScores.push(p.score);
|
for (const c of COLORS) if (colorComplete(p.wall, c)) bonus += COLOR_BONUS;
|
||||||
summary[p.seat].endBonuses = b;
|
p.score += bonus;
|
||||||
if (b.total) s.log.push(`${p.name} bonuses: rows +${b.rowPts}, columns +${b.colPts}, colours +${b.colorPts} → ${p.score}.`);
|
|
||||||
}
|
}
|
||||||
s.gameEnded = true;
|
s.gameEnded = true;
|
||||||
s.phase = 'gameOver';
|
s.phase = 'gameOver';
|
||||||
const top = finalRanking(s)[0];
|
|
||||||
s.log.push(`Game over — ${top.name} wins with ${top.score}.`);
|
|
||||||
} else {
|
} else {
|
||||||
s.round += 1;
|
s.round += 1;
|
||||||
s.current = s.startPlayer;
|
s.current = s.startPlayer;
|
||||||
|
|
@ -497,94 +301,6 @@ export function resolveRound(state, choices = null) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── move preview (for the hover UI and the verify script) ───────────────────
|
|
||||||
// What `move` would do for the current player, without changing anything:
|
|
||||||
// taken / placed / overflow, the floor slots the overflow (and marker) would
|
|
||||||
// fill and the penalty change, whether the line completes and — if so — the
|
|
||||||
// wall column and the points it would score at round end (lines above it
|
|
||||||
// that are already full tile first), plus which bonus sets it advances.
|
|
||||||
export function previewMove(state, move) {
|
|
||||||
const p = currentPlayer(state);
|
|
||||||
const free = isFreeWall(state);
|
|
||||||
const tiles = sourceTiles(state, move.source);
|
|
||||||
const taken = tiles.filter((t) => t === move.color).length;
|
|
||||||
const takesFirst = move.source.type === 'center' && state.centerHasFirst;
|
|
||||||
|
|
||||||
let placed = 0, lineAfter = 0, completes = false;
|
|
||||||
if (move.line !== 'floor') {
|
|
||||||
const cap = lineCapacity(move.line);
|
|
||||||
placed = Math.min(cap - p.lines[move.line].count, taken);
|
|
||||||
lineAfter = p.lines[move.line].count + placed;
|
|
||||||
completes = lineAfter === cap;
|
|
||||||
}
|
|
||||||
const overflow = taken - placed;
|
|
||||||
const floorBefore = p.floor.length;
|
|
||||||
const floorAdd = (takesFirst ? 1 : 0) + overflow;
|
|
||||||
const floorAfter = Math.min(FLOOR_SIZE, floorBefore + floorAdd);
|
|
||||||
const floorSlots = [];
|
|
||||||
for (let k = floorBefore; k < floorAfter; k++) floorSlots.push(k);
|
|
||||||
const floorDelta = floorPenaltyFor(floorAfter) - floorPenaltyFor(floorBefore);
|
|
||||||
const toLid = floorBefore + floorAdd - floorAfter;
|
|
||||||
|
|
||||||
const out = {
|
|
||||||
taken, placed, overflow, takesFirst, floorSlots, floorDelta, toLid,
|
|
||||||
lineAfter, completes, wallCol: null, wallPoints: 0, run: [],
|
|
||||||
rowAfter: 0, colAfter: 0, colorAfter: 0, endsGame: false, bonusHints: [],
|
|
||||||
};
|
|
||||||
if (!completes) return out;
|
|
||||||
|
|
||||||
// Simulate the earlier (higher) full lines tiling first on a scratch wall.
|
|
||||||
const scratch = { wall: p.wall.map((r) => r.slice()), wallColors: (p.wallColors ?? emptyWallColors()).map((r) => r.slice()), lines: p.lines };
|
|
||||||
for (let i = 0; i < move.line; i++) {
|
|
||||||
const l = p.lines[i];
|
|
||||||
if (l.color === null || l.count !== lineCapacity(i)) continue;
|
|
||||||
const opts = wallOptions(scratch, i, l.color, free);
|
|
||||||
if (!opts.length) continue;
|
|
||||||
const c = free ? defaultWallColumn(scratch, i, l.color, opts) : opts[0];
|
|
||||||
scratch.wall[i][c] = true; scratch.wallColors[i][c] = l.color;
|
|
||||||
}
|
|
||||||
const opts = wallOptions(scratch, move.line, move.color, free);
|
|
||||||
if (!opts.length) { out.completes = false; out.dumpRisk = true; return out; }
|
|
||||||
const col = free ? defaultWallColumn(scratch, move.line, move.color, opts) : opts[0];
|
|
||||||
scratch.wall[move.line][col] = true; scratch.wallColors[move.line][col] = move.color;
|
|
||||||
out.wallCol = col;
|
|
||||||
out.wallPoints = scorePlacement(scratch.wall, move.line, col);
|
|
||||||
out.run = placementRun(scratch.wall, move.line, col).cells;
|
|
||||||
const b = bonusStatus(scratch);
|
|
||||||
out.rowAfter = b.rows[move.line];
|
|
||||||
out.colAfter = b.cols[col];
|
|
||||||
out.colorAfter = b.colors[move.color];
|
|
||||||
out.endsGame = out.rowAfter === WALL_SIZE;
|
|
||||||
if (out.endsGame) out.bonusHints.push({ kind: 'row', pts: ROW_BONUS, done: true });
|
|
||||||
if (out.colAfter === WALL_SIZE) out.bonusHints.push({ kind: 'col', index: col, pts: COLUMN_BONUS, done: true });
|
|
||||||
else if (out.colAfter === WALL_SIZE - 1) out.bonusHints.push({ kind: 'col', index: col, pts: COLUMN_BONUS, done: false });
|
|
||||||
if (out.colorAfter === WALL_SIZE) out.bonusHints.push({ kind: 'color', color: move.color, pts: COLOR_BONUS, done: true });
|
|
||||||
else if (out.colorAfter === WALL_SIZE - 1) out.bonusHints.push({ kind: 'color', color: move.color, pts: COLOR_BONUS, done: false });
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── tile accounting (tests + the tracker panel) ──────────────────────────────
|
|
||||||
// Where every tile of each colour is right now.
|
|
||||||
export function tileCensus(state) {
|
|
||||||
const out = {};
|
|
||||||
for (const c of COLORS) out[c] = { bag: state.bag[c], lid: state.lid[c], table: 0, lines: 0, walls: 0, floors: 0 };
|
|
||||||
for (const f of state.factories) for (const t of f) out[t].table++;
|
|
||||||
for (const t of state.center) out[t].table++;
|
|
||||||
for (const p of state.players) {
|
|
||||||
for (const l of p.lines) if (l.color) out[l.color].lines += l.count;
|
|
||||||
for (let r = 0; r < WALL_SIZE; r++) for (let c = 0; c < WALL_SIZE; c++) {
|
|
||||||
const col = cellColor(p, r, c);
|
|
||||||
if (col) out[col].walls++;
|
|
||||||
}
|
|
||||||
for (const t of p.floor) if (t !== 'first') out[t].floors++;
|
|
||||||
}
|
|
||||||
for (const c of COLORS) {
|
|
||||||
const o = out[c];
|
|
||||||
o.total = o.bag + o.lid + o.table + o.lines + o.walls + o.floors;
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── end of game ──────────────────────────────────────────────────────────────
|
// ── end of game ──────────────────────────────────────────────────────────────
|
||||||
export function isGameOver(state) { return state.phase === 'gameOver'; }
|
export function isGameOver(state) { return state.phase === 'gameOver'; }
|
||||||
|
|
||||||
|
|
@ -600,5 +316,3 @@ export function finalRanking(state) {
|
||||||
.map((p) => ({ seat: p.seat, name: p.name, score: p.score, rows: completedRows(p) }))
|
.map((p) => ({ seat: p.seat, name: p.name, score: p.score, rows: completedRows(p) }))
|
||||||
.sort((a, b) => (b.score - a.score) || (b.rows - a.rows));
|
.sort((a, b) => (b.score - a.score) || (b.rows - a.rows));
|
||||||
}
|
}
|
||||||
|
|
||||||
export { wallColumnFor, emptyStats };
|
|
||||||
|
|
|
||||||
|
|
@ -1,174 +0,0 @@
|
||||||
// AzulSound.js — tiny Web Audio synths for glazed ceramic tiles. No audio
|
|
||||||
// files; silently does nothing without Web Audio or when the game is muted.
|
|
||||||
//
|
|
||||||
// clack(scene, { n, pitch }) tiles set down (n staggered clicks)
|
|
||||||
// tap(scene) a soft tap on the board (hover / pick)
|
|
||||||
// crunch(scene, { n }) tiles dropped on the floor line
|
|
||||||
// chime(scene, { pts }) a wall placement scoring (brighter for more)
|
|
||||||
// thunk(scene) the lid emptied back into the bag
|
|
||||||
// rattle(scene, { ms }) the bag shaken before a deal
|
|
||||||
// flourish(scene) an end-game bonus
|
|
||||||
|
|
||||||
function ctxOf(scene) {
|
|
||||||
const sm = scene.sound;
|
|
||||||
if (!sm || sm.mute || !sm.context || typeof sm.context.createOscillator !== 'function') return null;
|
|
||||||
return sm.context;
|
|
||||||
}
|
|
||||||
|
|
||||||
const noiseCache = new WeakMap();
|
|
||||||
function noise(ac) {
|
|
||||||
if (noiseCache.has(ac)) return noiseCache.get(ac);
|
|
||||||
const buf = ac.createBuffer(1, Math.ceil(ac.sampleRate * 0.6), ac.sampleRate);
|
|
||||||
const d = buf.getChannelData(0);
|
|
||||||
for (let i = 0; i < d.length; i++) d[i] = Math.random() * 2 - 1;
|
|
||||||
noiseCache.set(ac, buf);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Route through Phaser's master volume/mute node when it exposes one.
|
|
||||||
function out(scene, ac, gain) {
|
|
||||||
const sm = scene.sound;
|
|
||||||
const node = sm.masterVolumeNode ?? sm.destination ?? null;
|
|
||||||
const g = ac.createGain();
|
|
||||||
g.gain.value = node ? gain : gain * (sm.volume ?? 1);
|
|
||||||
g.connect(node ?? ac.destination);
|
|
||||||
return g;
|
|
||||||
}
|
|
||||||
|
|
||||||
// One ceramic click: a damped high partial pair plus a filtered noise tick.
|
|
||||||
function click(ac, dest, t0, { freq = 2900, decay = 0.05, vol = 1, body = 0.35 } = {}) {
|
|
||||||
for (const [f, a] of [[freq, 1], [freq * 1.47, 0.5], [freq * 0.52, body]]) {
|
|
||||||
const o = ac.createOscillator();
|
|
||||||
o.type = 'sine';
|
|
||||||
o.frequency.setValueAtTime(f, t0);
|
|
||||||
const g = ac.createGain();
|
|
||||||
g.gain.setValueAtTime(0, t0);
|
|
||||||
g.gain.linearRampToValueAtTime(vol * a, t0 + 0.002);
|
|
||||||
g.gain.exponentialRampToValueAtTime(0.0005, t0 + decay * (f < freq ? 1.6 : 1));
|
|
||||||
o.connect(g); g.connect(dest);
|
|
||||||
o.start(t0); o.stop(t0 + decay * 2 + 0.02);
|
|
||||||
}
|
|
||||||
const n = ac.createBufferSource();
|
|
||||||
n.buffer = noise(ac);
|
|
||||||
const hp = ac.createBiquadFilter(); hp.type = 'highpass'; hp.frequency.value = 3000;
|
|
||||||
const ng = ac.createGain();
|
|
||||||
ng.gain.setValueAtTime(vol * 0.6, t0);
|
|
||||||
ng.gain.exponentialRampToValueAtTime(0.0005, t0 + 0.018);
|
|
||||||
n.connect(hp); hp.connect(ng); ng.connect(dest);
|
|
||||||
n.start(t0, Math.random() * 0.4); n.stop(t0 + 0.03);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function clack(scene, { n = 1, pitch = 1, vol = 0.07, spread = 0.04 } = {}) {
|
|
||||||
const ac = ctxOf(scene);
|
|
||||||
if (!ac) return;
|
|
||||||
try {
|
|
||||||
const dest = out(scene, ac, vol);
|
|
||||||
const t0 = ac.currentTime + 0.005;
|
|
||||||
for (let k = 0; k < Math.min(n, 6); k++) {
|
|
||||||
click(ac, dest, t0 + k * spread + Math.random() * 0.012, { freq: (2500 + Math.random() * 700) * pitch, decay: 0.045 + Math.random() * 0.02 });
|
|
||||||
}
|
|
||||||
} catch (_) { /* audio is decoration */ }
|
|
||||||
}
|
|
||||||
|
|
||||||
export function tap(scene, { vol = 0.035 } = {}) {
|
|
||||||
const ac = ctxOf(scene);
|
|
||||||
if (!ac) return;
|
|
||||||
try {
|
|
||||||
click(ac, out(scene, ac, vol), ac.currentTime + 0.003, { freq: 1500 + Math.random() * 200, decay: 0.03, body: 0.6 });
|
|
||||||
} catch (_) { /* audio is decoration */ }
|
|
||||||
}
|
|
||||||
|
|
||||||
export function crunch(scene, { n = 1, vol = 0.09 } = {}) {
|
|
||||||
const ac = ctxOf(scene);
|
|
||||||
if (!ac) return;
|
|
||||||
try {
|
|
||||||
const dest = out(scene, ac, vol);
|
|
||||||
const t0 = ac.currentTime + 0.005;
|
|
||||||
for (let k = 0; k < Math.min(n, 5); k++) {
|
|
||||||
const t = t0 + k * 0.05;
|
|
||||||
const src = ac.createBufferSource();
|
|
||||||
src.buffer = noise(ac);
|
|
||||||
const bp = ac.createBiquadFilter(); bp.type = 'bandpass'; bp.frequency.value = 900 + Math.random() * 400; bp.Q.value = 0.9;
|
|
||||||
const g = ac.createGain();
|
|
||||||
g.gain.setValueAtTime(0, t);
|
|
||||||
g.gain.linearRampToValueAtTime(0.9, t + 0.004);
|
|
||||||
g.gain.exponentialRampToValueAtTime(0.001, t + 0.12);
|
|
||||||
src.connect(bp); bp.connect(g); g.connect(dest);
|
|
||||||
src.start(t, Math.random() * 0.4); src.stop(t + 0.14);
|
|
||||||
click(ac, dest, t, { freq: 1900, decay: 0.03, vol: 0.5 });
|
|
||||||
}
|
|
||||||
// A low thud under it all.
|
|
||||||
const o = ac.createOscillator(); const og = ac.createGain();
|
|
||||||
o.frequency.setValueAtTime(140, t0); o.frequency.exponentialRampToValueAtTime(60, t0 + 0.15);
|
|
||||||
og.gain.setValueAtTime(0.5, t0); og.gain.exponentialRampToValueAtTime(0.001, t0 + 0.18);
|
|
||||||
o.connect(og); og.connect(dest); o.start(t0); o.stop(t0 + 0.2);
|
|
||||||
} catch (_) { /* audio is decoration */ }
|
|
||||||
}
|
|
||||||
|
|
||||||
export function chime(scene, { pts = 1, vol = 0.06 } = {}) {
|
|
||||||
const ac = ctxOf(scene);
|
|
||||||
if (!ac) return;
|
|
||||||
try {
|
|
||||||
const dest = out(scene, ac, vol);
|
|
||||||
const t0 = ac.currentTime + 0.01;
|
|
||||||
// A rising pentatonic degree for bigger placements.
|
|
||||||
const scale = [0, 2, 4, 7, 9, 12, 14, 16, 19, 21];
|
|
||||||
const semis = scale[Math.min(scale.length - 1, Math.max(0, pts - 1))];
|
|
||||||
const base = 659.25 * 2 ** (semis / 12);
|
|
||||||
for (const [mul, a, dur] of [[1, 1, 0.9], [2.01, 0.35, 0.5], [3.02, 0.12, 0.3]]) {
|
|
||||||
const o = ac.createOscillator(); o.type = 'sine'; o.frequency.value = base * mul;
|
|
||||||
const g = ac.createGain();
|
|
||||||
g.gain.setValueAtTime(0, t0);
|
|
||||||
g.gain.linearRampToValueAtTime(a, t0 + 0.006);
|
|
||||||
g.gain.exponentialRampToValueAtTime(0.0005, t0 + dur);
|
|
||||||
o.connect(g); g.connect(dest); o.start(t0); o.stop(t0 + dur + 0.05);
|
|
||||||
}
|
|
||||||
} catch (_) { /* audio is decoration */ }
|
|
||||||
}
|
|
||||||
|
|
||||||
export function thunk(scene, { vol = 0.12 } = {}) {
|
|
||||||
const ac = ctxOf(scene);
|
|
||||||
if (!ac) return;
|
|
||||||
try {
|
|
||||||
const dest = out(scene, ac, vol);
|
|
||||||
const t0 = ac.currentTime + 0.01;
|
|
||||||
const o = ac.createOscillator(); const g = ac.createGain();
|
|
||||||
o.frequency.setValueAtTime(110, t0); o.frequency.exponentialRampToValueAtTime(48, t0 + 0.25);
|
|
||||||
g.gain.setValueAtTime(0.9, t0); g.gain.exponentialRampToValueAtTime(0.001, t0 + 0.3);
|
|
||||||
o.connect(g); g.connect(dest); o.start(t0); o.stop(t0 + 0.32);
|
|
||||||
rattle(scene, { ms: 350, vol: 0.05 });
|
|
||||||
} catch (_) { /* audio is decoration */ }
|
|
||||||
}
|
|
||||||
|
|
||||||
export function rattle(scene, { ms = 420, vol = 0.05 } = {}) {
|
|
||||||
const ac = ctxOf(scene);
|
|
||||||
if (!ac) return;
|
|
||||||
try {
|
|
||||||
const dest = out(scene, ac, vol);
|
|
||||||
const t0 = ac.currentTime + 0.01;
|
|
||||||
const n = Math.round(ms / 28);
|
|
||||||
for (let k = 0; k < n; k++) {
|
|
||||||
click(ac, dest, t0 + (k / n) * (ms / 1000) + Math.random() * 0.02, {
|
|
||||||
freq: 1700 + Math.random() * 1500, decay: 0.025, vol: 0.4 + Math.random() * 0.6, body: 0.2,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (_) { /* audio is decoration */ }
|
|
||||||
}
|
|
||||||
|
|
||||||
export function flourish(scene, { vol = 0.06 } = {}) {
|
|
||||||
const ac = ctxOf(scene);
|
|
||||||
if (!ac) return;
|
|
||||||
try {
|
|
||||||
const dest = out(scene, ac, vol);
|
|
||||||
const t0 = ac.currentTime + 0.01;
|
|
||||||
[523.25, 659.25, 783.99, 1046.5].forEach((f, i) => {
|
|
||||||
const o = ac.createOscillator(); o.type = 'triangle'; o.frequency.value = f;
|
|
||||||
const g = ac.createGain();
|
|
||||||
const t = t0 + i * 0.07;
|
|
||||||
g.gain.setValueAtTime(0, t);
|
|
||||||
g.gain.linearRampToValueAtTime(0.7, t + 0.01);
|
|
||||||
g.gain.exponentialRampToValueAtTime(0.0005, t + 0.7);
|
|
||||||
o.connect(g); g.connect(dest); o.start(t); o.stop(t + 0.75);
|
|
||||||
});
|
|
||||||
} catch (_) { /* audio is decoration */ }
|
|
||||||
}
|
|
||||||
|
|
@ -1,189 +0,0 @@
|
||||||
// AzulTiles.js — stable identities for the 100 physical tiles. Phaser-free.
|
|
||||||
//
|
|
||||||
// The engine only tracks colours and counts, but the scene wants every tile to
|
|
||||||
// be one persistent sprite that slides from plate to centre to line to wall.
|
|
||||||
// TileTracker keeps id → location and, given each new engine state, works out
|
|
||||||
// which ids moved where with the least disturbance:
|
|
||||||
// 1. every container (bag, lid, a plate, the centre, a pattern line, a wall
|
|
||||||
// cell, a floor line) keeps the ids it already holds that it still needs
|
|
||||||
// 2. the remaining ids are freed and handed to the containers short of tiles,
|
|
||||||
// colour by colour, preferring an obvious source (a seat's line feeds that
|
|
||||||
// seat's wall, a plate's leftovers feed the centre, …)
|
|
||||||
// Ids 0..99: colour = COLORS[floor(id / 20)].
|
|
||||||
//
|
|
||||||
// Location: { kind, seat?, index?, row?, col?, slot? } — see AzulLayout.tilePose.
|
|
||||||
|
|
||||||
import { COLORS, WALL_SIZE, TILES_PER_COLOR } from './AzulData.js';
|
|
||||||
import { cellColor } from './AzulLogic.js';
|
|
||||||
|
|
||||||
export const TILE_COUNT = COLORS.length * TILES_PER_COLOR;
|
|
||||||
export const colorOfId = (id) => COLORS[Math.floor(id / TILES_PER_COLOR)];
|
|
||||||
|
|
||||||
// Container key → { loc template, colours wanted (ordered when it matters) }.
|
|
||||||
function containers(state) {
|
|
||||||
const out = new Map();
|
|
||||||
const put = (key, base, colours, ordered) => out.set(key, { key, base, colours, ordered });
|
|
||||||
const bag = [], lid = [];
|
|
||||||
for (const c of COLORS) { for (let k = 0; k < state.bag[c]; k++) bag.push(c); for (let k = 0; k < state.lid[c]; k++) lid.push(c); }
|
|
||||||
put('bag', { kind: 'bag' }, bag, false);
|
|
||||||
put('lid', { kind: 'lid' }, lid, false);
|
|
||||||
state.factories.forEach((f, i) => put(`f${i}`, { kind: 'factory', index: i }, f.slice(), true));
|
|
||||||
put('c', { kind: 'center' }, state.center.slice(), false);
|
|
||||||
for (const p of state.players) {
|
|
||||||
for (let r = 0; r < WALL_SIZE; r++) {
|
|
||||||
const l = p.lines[r];
|
|
||||||
put(`l${p.seat}.${r}`, { kind: 'line', seat: p.seat, row: r }, l.color ? Array(l.count).fill(l.color) : [], true);
|
|
||||||
for (let c = 0; c < WALL_SIZE; c++) {
|
|
||||||
const col = cellColor(p, r, c);
|
|
||||||
if (col) put(`w${p.seat}.${r}.${c}`, { kind: 'wall', seat: p.seat, row: r, col: c }, [col], true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Floor keeps marker positions so slots line up with the board.
|
|
||||||
put(`fl${p.seat}`, { kind: 'floor', seat: p.seat }, p.floor.slice(), true);
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
// How natural it is for a freed tile from container `from` to fill `to`.
|
|
||||||
function affinity(from, to) {
|
|
||||||
if (!from) return 0;
|
|
||||||
if (from[0] === 'l' && to[0] === 'w' && from.slice(1).split('.').slice(0, 2).join('.') === to.slice(1).split('.').slice(0, 2).join('.')) return 9;
|
|
||||||
if (from[0] === 'f' && from[1] !== 'l' && to === 'c') return 6; // plate leftovers → centre
|
|
||||||
if (from === 'lid' && to === 'bag') return 6; // refill
|
|
||||||
if (from === 'bag' && to[0] === 'f' && to[1] !== 'l') return 6; // deal
|
|
||||||
if ((from[0] === 'l' || from.startsWith('fl')) && to === 'lid') return 5; // discards
|
|
||||||
if ((from[0] === 'f' || from === 'c') && (to[0] === 'l' || to.startsWith('fl'))) return 4; // a take
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class TileTracker {
|
|
||||||
constructor(state) {
|
|
||||||
this.where = new Array(TILE_COUNT).fill(null); // id → container key
|
|
||||||
this.slot = new Array(TILE_COUNT).fill(0); // id → slot within container
|
|
||||||
this.seq = new Array(TILE_COUNT).fill(0); // arrival order (centre sorting)
|
|
||||||
this.tick = 0;
|
|
||||||
for (let id = 0; id < TILE_COUNT; id++) this.where[id] = 'bag';
|
|
||||||
this.sync(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Location object for an id.
|
|
||||||
loc(id) {
|
|
||||||
const key = this.where[id];
|
|
||||||
const c = this._last?.get(key);
|
|
||||||
const base = c?.base ?? { kind: 'bag' };
|
|
||||||
return { ...base, slot: this.slot[id] };
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update to `state`. Returns [{ id, from, to, moved }] for every id whose
|
|
||||||
// container or slot changed (`moved` = container changed).
|
|
||||||
sync(state) {
|
|
||||||
const conts = containers(state);
|
|
||||||
const held = new Map();
|
|
||||||
for (let id = 0; id < TILE_COUNT; id++) {
|
|
||||||
const k = this.where[id];
|
|
||||||
if (!held.has(k)) held.set(k, []);
|
|
||||||
held.get(k).push(id);
|
|
||||||
}
|
|
||||||
const prevWhere = this.where.slice();
|
|
||||||
const prevSlot = this.slot.slice();
|
|
||||||
const prevConts = this._last;
|
|
||||||
const prevLoc = (id) => {
|
|
||||||
const c = prevConts?.get(prevWhere[id]);
|
|
||||||
return { ...(c?.base ?? { kind: 'bag' }), slot: prevSlot[id] };
|
|
||||||
};
|
|
||||||
|
|
||||||
// 1. keep what still fits.
|
|
||||||
const assigned = new Map(); // key → ids (ordered by need)
|
|
||||||
const freed = [];
|
|
||||||
for (const [key, c] of conts) {
|
|
||||||
const mine = (held.get(key) ?? []).slice().sort((a, b) => this.slot[a] - this.slot[b]);
|
|
||||||
const pool = mine.slice();
|
|
||||||
const ids = c.colours.map((col) => {
|
|
||||||
if (col === 'first') return 'first';
|
|
||||||
const i = pool.findIndex((id) => colorOfId(id) === col);
|
|
||||||
if (i < 0) return null;
|
|
||||||
return pool.splice(i, 1)[0];
|
|
||||||
});
|
|
||||||
assigned.set(key, ids);
|
|
||||||
freed.push(...pool);
|
|
||||||
held.delete(key);
|
|
||||||
}
|
|
||||||
for (const ids of held.values()) freed.push(...ids); // containers that vanished
|
|
||||||
|
|
||||||
// 2. hand freed ids to the gaps, best affinity first.
|
|
||||||
const gaps = [];
|
|
||||||
for (const [key, ids] of assigned) {
|
|
||||||
const c = conts.get(key);
|
|
||||||
ids.forEach((id, i) => { if (id === null) gaps.push({ key, i, color: c.colours[i] }); });
|
|
||||||
}
|
|
||||||
const pairs = [];
|
|
||||||
for (const g of gaps) {
|
|
||||||
for (const id of freed) {
|
|
||||||
if (colorOfId(id) !== g.color) continue;
|
|
||||||
pairs.push({ g, id, a: affinity(prevWhere[id], g.key) });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pairs.sort((x, y) => y.a - x.a || x.id - y.id);
|
|
||||||
const used = new Set();
|
|
||||||
for (const { g, id } of pairs) {
|
|
||||||
if (g.done || used.has(id)) continue;
|
|
||||||
assigned.get(g.key)[g.i] = id;
|
|
||||||
g.done = true;
|
|
||||||
used.add(id);
|
|
||||||
}
|
|
||||||
if (gaps.some((g) => !g.done)) throw new Error('TileTracker: could not place every tile');
|
|
||||||
|
|
||||||
// 3. write back, with slots.
|
|
||||||
this.tick++;
|
|
||||||
for (const [key, ids] of assigned) {
|
|
||||||
const c = conts.get(key);
|
|
||||||
let list = ids;
|
|
||||||
if (key === 'c') {
|
|
||||||
// Centre: grouped by colour, stable within a colour (arrival order).
|
|
||||||
for (const id of ids) if (prevWhere[id] !== 'c') this.seq[id] = this.tick * 1000 + id;
|
|
||||||
list = ids.slice().sort((a, b) => COLORS.indexOf(colorOfId(a)) - COLORS.indexOf(colorOfId(b)) || this.seq[a] - this.seq[b]);
|
|
||||||
const offset = state.centerHasFirst ? 1 : 0; // the marker sits first
|
|
||||||
list.forEach((id, i) => { this.where[id] = key; this.slot[id] = i + offset; });
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
ids.forEach((id, i) => {
|
|
||||||
if (id === 'first') return;
|
|
||||||
this.where[id] = key;
|
|
||||||
this.slot[id] = (key === 'bag' || key === 'lid') ? 0 : i;
|
|
||||||
});
|
|
||||||
void c;
|
|
||||||
}
|
|
||||||
this._last = conts;
|
|
||||||
|
|
||||||
const changes = [];
|
|
||||||
for (let id = 0; id < TILE_COUNT; id++) {
|
|
||||||
const moved = prevWhere[id] !== this.where[id];
|
|
||||||
if (moved || prevSlot[id] !== this.slot[id]) changes.push({ id, from: prevLoc(id), to: this.loc(id), moved, fromKey: prevWhere[id], toKey: this.where[id] });
|
|
||||||
}
|
|
||||||
return changes;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ids currently in a container key (e.g. 'f3', 'c', 'l0.2', 'fl1').
|
|
||||||
idsIn(key) {
|
|
||||||
const out = [];
|
|
||||||
for (let id = 0; id < TILE_COUNT; id++) if (this.where[id] === key) out.push(id);
|
|
||||||
return out.sort((a, b) => this.slot[a] - this.slot[b]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Census by container kind, for tests.
|
|
||||||
counts() {
|
|
||||||
const out = {};
|
|
||||||
for (let id = 0; id < TILE_COUNT; id++) out[this.where[id]] = (out[this.where[id]] ?? 0) + 1;
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Where the first-player marker sits: { kind:'center', slot:0 } or floor.
|
|
||||||
static markerLoc(state) {
|
|
||||||
if (state.centerHasFirst) return { kind: 'center', slot: 0 };
|
|
||||||
for (const p of state.players) {
|
|
||||||
const k = p.floor.indexOf('first');
|
|
||||||
if (k >= 0) return { kind: 'floor', seat: p.seat, slot: k };
|
|
||||||
}
|
|
||||||
return { kind: 'center', slot: 0, hidden: true };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -4,11 +4,11 @@
|
||||||
**Cell size:** 96 × 96 px (transparent PNG)
|
**Cell size:** 96 × 96 px (transparent PNG)
|
||||||
**Total frames:** 6, single row (sheet is 576 × 96)
|
**Total frames:** 6, single row (sheet is 576 × 96)
|
||||||
|
|
||||||
The committed sheet holds the finished azulejo tile art. `AzulArt.js` bakes
|
A **temporary** placeholder sheet is already committed (flat colours with a
|
||||||
each frame into a glazed tile texture (rounded corners, bevel, sheen and a soft
|
diamond motif, generated by `tools` PIL script). Replace it with finished
|
||||||
shadow) and uses washed-out copies as the wall "ghosts" on every board, so new
|
azulejo-style tile art at the same dimensions and frame order and the game picks
|
||||||
art at the same dimensions and frame order is picked up automatically. If the
|
it up automatically — no code changes needed. If the file is ever missing, the
|
||||||
file is ever missing, procedural azulejo faces are drawn instead.
|
scene falls back to vector tiles.
|
||||||
|
|
||||||
## Frame order
|
## Frame order
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,9 +33,7 @@ On your turn you do exactly one thing: **take all tiles of a single colour** fro
|
||||||
- Click any tile in a **factory display** to take *every* tile of that colour there. The factory's other tiles slide into the **Centre**.
|
- Click any tile in a **factory display** to take *every* tile of that colour there. The factory's other tiles slide into the **Centre**.
|
||||||
- Or click a colour in the **Centre** to take all of it. The first person to take from the Centre each round also picks up the **first-player marker** (the "1" tile) — it drops onto their floor line for a small penalty, but it makes them the start player next round.
|
- Or click a colour in the **Centre** to take all of it. The first person to take from the Centre each round also picks up the **first-player marker** (the "1" tile) — it drops onto their floor line for a small penalty, but it makes them the start player next round.
|
||||||
|
|
||||||
Then choose where the tiles go: click a glowing **pattern line**, or the **floor line** — or simply **drag** the tiles there.
|
Then choose where the tiles go: click a glowing **pattern line**, or the **floor line**.
|
||||||
|
|
||||||
**Before you commit, hover a line.** Ghost tiles show exactly where your tiles would land, any spill onto the floor shows in red, and the work-order panel spells it out: how many points the line would score when it tiles, what it costs on the floor, and whether it brings a column or a colour close to its bonus. Changed your mind? Click the tiles again (or press **Esc**) to put them back. Made a move you regret? **Undo** is there until the next player actually moves.
|
|
||||||
|
|
||||||
Rules for pattern lines:
|
Rules for pattern lines:
|
||||||
- The line must be empty or already holding that colour.
|
- The line must be empty or already holding that colour.
|
||||||
|
|
@ -71,25 +69,6 @@ Highest total wins; ties go to whoever completed more horizontal rows.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Around the Workshop
|
|
||||||
|
|
||||||
- **Tile Tracker** (bottom left): how many of each colour are still in the bag, in the lid, on the table and set on walls. Good tilers count tiles — now everyone can.
|
|
||||||
- **The bag and the lid**: hover either for exact counts. When the bag runs dry, the lid is poured back in.
|
|
||||||
- **Bonus badges**: each board shows the end-game bonus it has already locked in, and a ★ for every column or colour that is one tile away.
|
|
||||||
- **Opponents' boards**: hover one to see it full-size.
|
|
||||||
- **Order Book** (right): the latest moves; **Log** shows the whole game.
|
|
||||||
- **Menu**: opponent speed, move preview, undo, the tracker, colour-blind symbols, and the wall variant.
|
|
||||||
|
|
||||||
**Keyboard:** **1–9** pick a plate (press again for its next colour), **C** the centre, **←/→** change colour, **↑/↓** choose a line, **Enter** place, **F** floor, **Z** undo, **L** log, **Esc** cancel / menu.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## The Free Wall (variant)
|
|
||||||
|
|
||||||
Turn on the **free (grey) wall** in the Menu for your next game. The wall has no printed colours: when a pattern line tiles, *you* choose which space in that row it goes to — but each colour may appear only once in every row **and** every column. A pattern line can't take a colour that row already has, and if a full line finds no legal space at all, its tiles crash onto your floor. Glowing spaces with their points show your options.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Inês's Advice
|
## Inês's Advice
|
||||||
|
|
||||||
- **Match the line to the haul.** Need 3 tiles to fill row 3? Take a pile of exactly 3. Overfilling feeds your floor line.
|
- **Match the line to the haul.** Need 3 tiles to fill row 3? Take a pile of exactly 3. Overfilling feeds your floor line.
|
||||||
|
|
|
||||||
|
|
@ -1,83 +0,0 @@
|
||||||
// Baccarat table art: burgundy felt, three curved betting boxes per seat
|
|
||||||
// (PLAYER / BANKER / TIE), and the dealer's PLAYER and BANKER card boxes.
|
|
||||||
|
|
||||||
import { prepareCasinoArt, bakeCasinoTable, poly, rr, drawArcText } from '../../ui/casino/CasinoArt.js';
|
|
||||||
import {
|
|
||||||
VIEW, SEAT_ANGLES, BANDS, BET_TYPES, BET_META, boxOutline, handBoxRect, handCardPose,
|
|
||||||
CARD_W, CARD_H, FELT_TEXT, TRAY, SHOE, DISCARD, PLACARD,
|
|
||||||
} from './BaccaratTable.js';
|
|
||||||
|
|
||||||
function hexToRgba(hex, a) {
|
|
||||||
const n = parseInt(hex.slice(1), 16);
|
|
||||||
return `rgba(${(n >> 16) & 255},${(n >> 8) & 255},${n & 255},${a})`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function drawMarkings(ctx) {
|
|
||||||
SEAT_ANGLES.forEach((theta, seat) => {
|
|
||||||
for (const type of BET_TYPES) {
|
|
||||||
const meta = BET_META[type];
|
|
||||||
poly(ctx, boxOutline(seat, type));
|
|
||||||
ctx.fillStyle = hexToRgba(meta.felt, 0.09);
|
|
||||||
ctx.fill();
|
|
||||||
ctx.lineWidth = 2.5;
|
|
||||||
ctx.strokeStyle = hexToRgba(meta.felt, 0.85);
|
|
||||||
ctx.stroke();
|
|
||||||
poly(ctx, boxOutline(seat, type, 0.012));
|
|
||||||
ctx.lineWidth = 1;
|
|
||||||
ctx.strokeStyle = 'rgba(242,234,216,0.22)';
|
|
||||||
ctx.stroke();
|
|
||||||
const { r0, r1 } = BANDS[type];
|
|
||||||
drawArcText(ctx, {
|
|
||||||
text: meta.label, r: (r0 + r1) / 2, size: type === 'tie' ? 15 : 16, color: meta.felt,
|
|
||||||
alpha: 0.9, spacing: 1.08, bold: true, centerDeg: theta,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
for (const side of ['player', 'banker']) {
|
|
||||||
const meta = BET_META[side];
|
|
||||||
const b = handBoxRect(side);
|
|
||||||
rr(ctx, b.x - b.w / 2, b.y - b.h / 2, b.w, b.h, 12 * b.s);
|
|
||||||
ctx.fillStyle = hexToRgba(meta.felt, 0.08);
|
|
||||||
ctx.fill();
|
|
||||||
ctx.lineWidth = 2.5;
|
|
||||||
ctx.strokeStyle = hexToRgba(meta.felt, 0.8);
|
|
||||||
ctx.stroke();
|
|
||||||
ctx.save();
|
|
||||||
ctx.translate(b.x, b.y);
|
|
||||||
ctx.scale(b.s, b.s * VIEW.squash);
|
|
||||||
ctx.font = 'bold 30px "Julius Sans One", sans-serif';
|
|
||||||
ctx.textAlign = 'center';
|
|
||||||
ctx.textBaseline = 'middle';
|
|
||||||
ctx.fillStyle = hexToRgba(meta.felt, 0.55);
|
|
||||||
ctx.fillText(meta.label, 0, 0);
|
|
||||||
ctx.restore();
|
|
||||||
|
|
||||||
// third-card spot (sideways)
|
|
||||||
const t = handCardPose(side, 2);
|
|
||||||
ctx.save();
|
|
||||||
ctx.translate(t.x, t.y);
|
|
||||||
ctx.rotate(t.rot);
|
|
||||||
ctx.scale(t.s, t.s * VIEW.squash);
|
|
||||||
ctx.setLineDash([8, 6]);
|
|
||||||
rr(ctx, -CARD_W / 2 - 6, -CARD_H / 2 - 6, CARD_W + 12, CARD_H + 12, 10);
|
|
||||||
ctx.lineWidth = 2 / t.s;
|
|
||||||
ctx.strokeStyle = hexToRgba(meta.felt, 0.6);
|
|
||||||
ctx.stroke();
|
|
||||||
ctx.setLineDash([]);
|
|
||||||
ctx.restore();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function prepareBaccaratArt(scene) {
|
|
||||||
await prepareCasinoArt(scene);
|
|
||||||
bakeCasinoTable(scene, 'bac-table', {
|
|
||||||
felt: '#5c1020',
|
|
||||||
markings: drawMarkings,
|
|
||||||
text: FELT_TEXT,
|
|
||||||
tray: TRAY,
|
|
||||||
shoe: SHOE,
|
|
||||||
discard: DISCARD,
|
|
||||||
placard: PLACARD,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,68 +0,0 @@
|
||||||
// Baccarat scoreboard "roads" — pure, so tools/verifyBaccarat.js can test them.
|
|
||||||
//
|
|
||||||
// history: array of coup outcomes, oldest first: 'player' | 'banker' | 'tie'.
|
|
||||||
//
|
|
||||||
// Bead plate: every coup in order, filling columns top-to-bottom (6 rows),
|
|
||||||
// showing only the most recent whole columns that fit.
|
|
||||||
// Big road: one column per streak of the same winner (P or B). Ties don't
|
|
||||||
// take a cell — they mark the latest cell (a green slash). A streak
|
|
||||||
// longer than the column turns right along its last row ("dragon tail").
|
|
||||||
// Each new streak starts in the column after the previous streak began.
|
|
||||||
|
|
||||||
export function counts(history) {
|
|
||||||
const c = { player: 0, banker: 0, tie: 0 };
|
|
||||||
for (const h of history) c[h]++;
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function beadPlate(history, rows = 6, cols = 10) {
|
|
||||||
const usedCols = Math.ceil(history.length / rows);
|
|
||||||
const dropCols = Math.max(0, usedCols - cols);
|
|
||||||
const start = dropCols * rows;
|
|
||||||
return history.slice(start).map((outcome, k) => ({ col: Math.floor(k / rows), row: k % rows, outcome }));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function bigRoad(history, rows = 6) {
|
|
||||||
const cells = [];
|
|
||||||
const taken = new Set();
|
|
||||||
const key = (c, r) => `${c},${r}`;
|
|
||||||
let last = null; // last placed cell
|
|
||||||
let streakCol = -1; // column where the current streak started
|
|
||||||
let pendingTies = 0; // ties before the first P/B
|
|
||||||
for (const outcome of history) {
|
|
||||||
if (outcome === 'tie') {
|
|
||||||
if (last) last.ties++;
|
|
||||||
else pendingTies++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let col, row;
|
|
||||||
if (last && last.outcome === outcome) {
|
|
||||||
// continue the streak: down if free, otherwise turn right
|
|
||||||
if (!last.tail && last.row + 1 < rows && !taken.has(key(last.col, last.row + 1))) {
|
|
||||||
col = last.col; row = last.row + 1;
|
|
||||||
} else {
|
|
||||||
col = last.col + 1; row = last.row;
|
|
||||||
while (taken.has(key(col, row))) col++;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
streakCol += 1;
|
|
||||||
col = streakCol; row = 0;
|
|
||||||
while (taken.has(key(col, row))) { streakCol++; col = streakCol; }
|
|
||||||
}
|
|
||||||
const cell = { col, row, outcome, ties: pendingTies, tail: last && last.outcome === outcome && col !== last.col };
|
|
||||||
if (last && last.outcome === outcome && last.tail) cell.tail = true;
|
|
||||||
pendingTies = 0;
|
|
||||||
taken.add(key(col, row));
|
|
||||||
cells.push(cell);
|
|
||||||
last = cell;
|
|
||||||
}
|
|
||||||
return cells;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The big-road cells that fit in a window of `cols` columns (most recent).
|
|
||||||
export function bigRoadWindow(history, rows = 6, cols = 18) {
|
|
||||||
const cells = bigRoad(history, rows);
|
|
||||||
const maxCol = cells.reduce((m, c) => Math.max(m, c.col), -1);
|
|
||||||
const offset = Math.max(0, maxCol + 1 - cols);
|
|
||||||
return cells.filter(c => c.col >= offset).map(c => ({ ...c, col: c.col - offset }));
|
|
||||||
}
|
|
||||||
|
|
@ -1,116 +0,0 @@
|
||||||
// Baccarat table layout — Phaser-free so tools/verifyBaccarat.js can test it.
|
|
||||||
//
|
|
||||||
// Shared perspective + rail geometry come from src/ui/casino/CasinoGeometry.js
|
|
||||||
// (re-exported). Every seat has three curved betting boxes in concentric bands —
|
|
||||||
// PLAYER nearest the rail, then BANKER, then TIE — and the dealer row holds the
|
|
||||||
// PLAYER and BANKER card boxes.
|
|
||||||
|
|
||||||
import { polar, project, toPolar, feltSector } from '../../ui/casino/CasinoGeometry.js';
|
|
||||||
import { BET } from './BaccaratLogic.js';
|
|
||||||
|
|
||||||
export * from '../../ui/casino/CasinoGeometry.js';
|
|
||||||
|
|
||||||
export const CARD_W = 96;
|
|
||||||
export const CARD_H = 134;
|
|
||||||
|
|
||||||
// Same seating as Blackjack: 0 = human bottom-centre, then outward-alternating.
|
|
||||||
export const SEAT_ANGLES = [0, 25, -25, 49, -49, 71, -71];
|
|
||||||
export const DISPLAY_ORDER = [5, 3, 1, 0, 2, 4, 6];
|
|
||||||
|
|
||||||
// Concentric betting bands (table-space radii) and each box's half-width in degrees.
|
|
||||||
export const BANDS = {
|
|
||||||
[BET.PLAYER]: { r0: 0.846, r1: 0.952 },
|
|
||||||
[BET.BANKER]: { r0: 0.732, r1: 0.836 },
|
|
||||||
[BET.TIE]: { r0: 0.632, r1: 0.722 },
|
|
||||||
};
|
|
||||||
export const BOX_HALF_DEG = 10;
|
|
||||||
export const BET_TYPES = [BET.PLAYER, BET.BANKER, BET.TIE];
|
|
||||||
|
|
||||||
export const BET_META = {
|
|
||||||
[BET.PLAYER]: { label: 'PLAYER', short: 'P', color: 0x3d7fd6, hex: '#4a90d9', felt: '#5d9be6' },
|
|
||||||
[BET.BANKER]: { label: 'BANKER', short: 'B', color: 0xd64545, hex: '#e05c5c', felt: '#ee6a6a' },
|
|
||||||
[BET.TIE]: { label: 'TIE 8:1', short: 'T', color: 0x3aa35c, hex: '#5cb85c', felt: '#6cd08a' },
|
|
||||||
};
|
|
||||||
|
|
||||||
const PORTRAITS = [
|
|
||||||
{ x: 160, y: 1013, r: 50 }, // 0 human — in the dock
|
|
||||||
{ x: 1556, y: 812, r: 56 }, // 1 right-bottom
|
|
||||||
{ x: 364, y: 812, r: 56 }, // 2 left-bottom
|
|
||||||
{ x: 1786, y: 640, r: 56 }, // 3 right-mid
|
|
||||||
{ x: 134, y: 640, r: 56 }, // 4 left-mid
|
|
||||||
{ x: 1810, y: 330, r: 56 }, // 5 right-top
|
|
||||||
{ x: 110, y: 330, r: 56 }, // 6 left-top
|
|
||||||
];
|
|
||||||
|
|
||||||
export function seatPortrait(seat) {
|
|
||||||
return { ...PORTRAITS[seat] };
|
|
||||||
}
|
|
||||||
|
|
||||||
// Centre of a seat's betting box (where its chips stack).
|
|
||||||
export function boxCenter(seat, type) {
|
|
||||||
const { r0, r1 } = BANDS[type];
|
|
||||||
return polar((r0 + r1) / 2, SEAT_ANGLES[seat]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Projected outline of a seat's betting box.
|
|
||||||
export function boxOutline(seat, type, inset = 0) {
|
|
||||||
const { r0, r1 } = BANDS[type];
|
|
||||||
const th = SEAT_ANGLES[seat];
|
|
||||||
return feltSector(r0 + inset, r1 - inset, th - BOX_HALF_DEG + inset * 40, th + BOX_HALF_DEG - inset * 40);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Which betting box (if any) is under a screen point? → { seat, type } | null
|
|
||||||
export function hitBox(x, y) {
|
|
||||||
const { r, theta, v } = toPolar(x, y);
|
|
||||||
if (v < 0) return null;
|
|
||||||
const type = BET_TYPES.find(t => r >= BANDS[t].r0 && r <= BANDS[t].r1);
|
|
||||||
if (!type) return null;
|
|
||||||
const seat = SEAT_ANGLES.findIndex(a => Math.abs(theta - a) <= BOX_HALF_DEG);
|
|
||||||
return seat === -1 ? null : { seat, type };
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Dealer row: PLAYER (left) and BANKER (right) card boxes ──────────────────
|
|
||||||
export const HAND_V = 0.245;
|
|
||||||
export const HAND_U = 0.21;
|
|
||||||
export const HAND_BOOST = 1.12;
|
|
||||||
export const CARD_GAP = 46; // px @ s between the first two cards
|
|
||||||
|
|
||||||
export function handCenter(side) {
|
|
||||||
const p = project(side === 'player' ? -HAND_U : HAND_U, HAND_V);
|
|
||||||
return { ...p, s: p.s * HAND_BOOST };
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pose of card i (0, 1 = the first two; 2 = the sideways third card).
|
|
||||||
export function handCardPose(side, i) {
|
|
||||||
const c = handCenter(side);
|
|
||||||
const out = side === 'player' ? -1 : 1; // third card sits on the outer side
|
|
||||||
if (i < 2) return { x: c.x + (i - 0.5) * CARD_GAP * c.s, y: c.y, rot: 0, s: c.s };
|
|
||||||
return { x: c.x + out * (CARD_GAP / 2 + CARD_W * 0.5 + CARD_H * 0.45) * c.s, y: c.y + 4, rot: Math.PI / 2, s: c.s };
|
|
||||||
}
|
|
||||||
|
|
||||||
// The printed card box around both first cards (+ the third-card spot).
|
|
||||||
export function handBoxRect(side) {
|
|
||||||
const c = handCenter(side);
|
|
||||||
return { x: c.x, y: c.y, w: (CARD_W + CARD_GAP + 26) * c.s, h: (CARD_H + 18) * c.s * 0.9, s: c.s };
|
|
||||||
}
|
|
||||||
|
|
||||||
export const TOTAL_BADGE_DY = 92; // px @ s below the hand centre (just under the card box)
|
|
||||||
|
|
||||||
// ── Furniture ────────────────────────────────────────────────────────────────
|
|
||||||
export const SHOE = { u: 0.47, v: 0.085 };
|
|
||||||
export const DISCARD = { u: -0.47, v: 0.085 };
|
|
||||||
export const PLACARD = { u: -0.335, v: 0.035, lines: ['TABLE LIMITS', '$5 – $500'] };
|
|
||||||
|
|
||||||
export const FELT_TEXT = [
|
|
||||||
{ text: 'BANKER PAYS 19 TO 20 · TIE PAYS 8 TO 1', r: 0.565, size: 18, color: '#f2ead8', alpha: 0.75, spacing: 0.96 },
|
|
||||||
];
|
|
||||||
|
|
||||||
// The tally readout panel (Equation Ribbon) sits between the hands and the seats.
|
|
||||||
export const READOUT = { x: 960, y: 430, w: 300, h: 110 };
|
|
||||||
|
|
||||||
// ── Scoreboard (standing LED board above the dealer edge, top-right) ─────────
|
|
||||||
export const BOARD = { x: 1342, y: 10, cell: 18, rows: 6, beadCols: 10, roadCols: 18, pad: 12, header: 28 };
|
|
||||||
export function boardSize() {
|
|
||||||
const { cell, rows, beadCols, roadCols, pad, header } = BOARD;
|
|
||||||
return { w: pad * 3 + (beadCols + roadCols) * cell, h: header + rows * cell + pad * 2 };
|
|
||||||
}
|
|
||||||
|
|
@ -1,427 +1,95 @@
|
||||||
// BackgammonAI.js — skill 1–5 checker play and cube decisions. Phaser-free.
|
|
||||||
//
|
|
||||||
// Everything works on mover-perspective Int8Array boards (see BackgammonLogic).
|
|
||||||
// evaluate(me, op) = P(me wins) with op ON ROLL, i.e. right after I moved.
|
|
||||||
//
|
|
||||||
// race (no contact) bear-off table when both sides are home (exact
|
|
||||||
// one-sided expected rolls + variance), else a pip race
|
|
||||||
// formula with the on-roll edge.
|
|
||||||
// contact a pip-equivalent score: pips, made points (by value),
|
|
||||||
// primes in front of trapped checkers, shot-counted blot
|
|
||||||
// risk (how many of the 36 rolls hit each blot, honouring
|
|
||||||
// blocks, combination paths and the bar), checkers on the
|
|
||||||
// bar against the closed home board, stacking — then a
|
|
||||||
// logistic to a probability.
|
|
||||||
//
|
|
||||||
// Skill ladder
|
|
||||||
// 5 full evaluator + 2-ply: the top 8 candidates are re-scored against every
|
|
||||||
// one of the opponent's 21 rolls and their best reply (≈61% vs skill 4)
|
|
||||||
// 4 full evaluator, 1-ply
|
|
||||||
// 3 simple evaluator (no shot counting, pip-only races)
|
|
||||||
// 2 simple evaluator + noise
|
|
||||||
// 1 simple evaluator + heavy noise + occasional loose plays
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
WHITE, BLACK, other, boardsFor, enumerateTurns, toIdx, pipP, canBearOffP,
|
cloneState, getValidMoves, applyMove, computePipCount,
|
||||||
} from './BackgammonLogic.js';
|
} from './BackgammonLogic.js';
|
||||||
import * as Bearoff from './BackgammonBearoff.js';
|
|
||||||
|
|
||||||
// ── tuning ───────────────────────────────────────────────────────────────────
|
// Returns an ordered array of moves for the AI (Black) to execute.
|
||||||
export const TUNE = {
|
export function chooseMoves(state) {
|
||||||
K: 13, // pip-equivalent score → logistic scale
|
const sequences = generateSequences(state);
|
||||||
onRoll: 5, // pips the side on roll is worth in contact
|
if (sequences.length === 0) return [];
|
||||||
prime: [0, 0, 1, 3, 6.5, 11, 17],
|
|
||||||
trappedBonus: 0.3,
|
|
||||||
blotBase: 4,
|
|
||||||
blotPerPip: 0.55,
|
|
||||||
blotHome: 1.6, // extra cost per opponent home point made
|
|
||||||
oppBlotW: 0.22,
|
|
||||||
barBase: 3,
|
|
||||||
barHome: 0.95,
|
|
||||||
stack: 1.1,
|
|
||||||
backStuck: 0.45,
|
|
||||||
pvScale: 1,
|
|
||||||
primeScale: 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
// value of a made point by its own point index (0 = ace … 23 = 24-point)
|
|
||||||
const PV = [
|
|
||||||
1.0, 2.2, 3.4, 5.0, 7.0, 6.0, // home board: 1…6
|
|
||||||
5.5, 3.6, 2.4, 2.0, 1.6, 1.4, // outer: bar(7) … 12
|
|
||||||
1.6, 1.0, 1.0, 1.0, 1.0, 1.2, // 13 (mid) … 18
|
|
||||||
3.0, 4.2, 3.6, 2.6, 1.6, 1.0, // anchors in the opponent's home: 19…24
|
|
||||||
];
|
|
||||||
const PV_SIMPLE = [
|
|
||||||
0.5, 1.5, 2.5, 3.5, 4.5, 4.0,
|
|
||||||
3.5, 2.5, 1.5, 1.0, 1.0, 1.0,
|
|
||||||
1.0, 0.5, 0.5, 0.5, 0.5, 0.5,
|
|
||||||
1.5, 2.0, 2.0, 1.5, 1.0, 0.5,
|
|
||||||
];
|
|
||||||
|
|
||||||
const ROLLS = [];
|
|
||||||
for (let a = 1; a <= 6; a++) for (let b = a; b <= 6; b++) ROLLS.push({ a, b, w: a === b ? 1 : 2 });
|
|
||||||
export { ROLLS };
|
|
||||||
|
|
||||||
const logistic = (x) => 1 / (1 + Math.exp(-x));
|
|
||||||
const now = () => (typeof performance !== 'undefined' ? performance.now() : Date.now());
|
|
||||||
|
|
||||||
// ── helpers ──────────────────────────────────────────────────────────────────
|
|
||||||
export function hasContact(me, op) {
|
|
||||||
let mMax = -1, oMax = -1;
|
|
||||||
for (let i = 24; i >= 0; i--) if (me[i]) { mMax = i; break; }
|
|
||||||
for (let i = 24; i >= 0; i--) if (op[i]) { oMax = i; break; }
|
|
||||||
if (mMax < 0 || oMax < 0) return false;
|
|
||||||
return mMax + oMax >= 24;
|
|
||||||
}
|
|
||||||
|
|
||||||
function homeClosed(b) {
|
|
||||||
let n = 0;
|
|
||||||
for (let i = 0; i < 6; i++) if (b[i] >= 2) n++;
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Shots the opponent (op, on roll) has at my blots. Returns
|
|
||||||
// { union, per: Float32Array(24) } in roll counts out of 36.
|
|
||||||
const perBuf = new Float32Array(24);
|
|
||||||
const hitBuf = new Uint8Array(24);
|
|
||||||
export function shotInfo(me, op) {
|
|
||||||
const per = perBuf; per.fill(0);
|
|
||||||
let blotCount = 0;
|
|
||||||
for (let i = 0; i < 24; i++) if (me[i] === 1) blotCount++;
|
|
||||||
if (!blotCount) return { union: 0, per, blots: 0 };
|
|
||||||
// op-perspective helpers: target t (op index) holds my blot when me[23 − t] === 1
|
|
||||||
const open = (t) => t >= 0 && t <= 23 && me[23 - t] < 2;
|
|
||||||
const blotAt = (t) => t >= 0 && t <= 23 && me[23 - t] === 1;
|
|
||||||
const srcs = [];
|
|
||||||
for (let j = 0; j < 24; j++) if (op[j]) srcs.push(j);
|
|
||||||
const bar = op[24];
|
|
||||||
let union = 0;
|
|
||||||
for (const { a, b, w } of ROLLS) {
|
|
||||||
hitBuf.fill(0);
|
|
||||||
let any = false;
|
|
||||||
const mark = (t) => { if (blotAt(t)) { hitBuf[23 - t] = 1; any = true; } };
|
|
||||||
if (a === b) {
|
|
||||||
const d = a;
|
|
||||||
if (bar > 0) {
|
|
||||||
const e = 24 - d;
|
|
||||||
if (open(e)) {
|
|
||||||
mark(e);
|
|
||||||
const left = 4 - Math.min(bar, 4);
|
|
||||||
// the entered checker (and, with one on the bar, any other checker) continues
|
|
||||||
let t = e;
|
|
||||||
for (let k = 0; k < left; k++) { t -= d; if (!open(t)) break; mark(t); }
|
|
||||||
if (bar === 1) {
|
|
||||||
for (const j of srcs) {
|
|
||||||
let tt = j;
|
|
||||||
for (let k = 0; k < 3; k++) { tt -= d; if (!open(tt)) break; mark(tt); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (const j of srcs) {
|
|
||||||
let t = j;
|
|
||||||
for (let k = 0; k < 4; k++) { t -= d; if (!open(t)) break; mark(t); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (bar >= 2) {
|
|
||||||
if (open(24 - a)) mark(24 - a);
|
|
||||||
if (open(24 - b)) mark(24 - b);
|
|
||||||
} else if (bar === 1) {
|
|
||||||
for (const [x, y] of [[a, b], [b, a]]) {
|
|
||||||
const e = 24 - x;
|
|
||||||
if (!open(e)) continue;
|
|
||||||
mark(e);
|
|
||||||
if (open(e - y)) mark(e - y);
|
|
||||||
for (const j of srcs) if (open(j - y)) mark(j - y);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (const j of srcs) {
|
|
||||||
mark(j - a); mark(j - b);
|
|
||||||
if ((open(j - a) || open(j - b)) && open(j - a - b)) mark(j - a - b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (any) {
|
|
||||||
union += w;
|
|
||||||
for (let i = 0; i < 24; i++) if (hitBuf[i]) per[i] += w;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return { union, per, blots: blotCount };
|
|
||||||
}
|
|
||||||
|
|
||||||
function primeValue(me, op) {
|
|
||||||
let best = 0;
|
|
||||||
let i = 0;
|
|
||||||
while (i < 24) {
|
|
||||||
if (me[i] < 2) { i++; continue; }
|
|
||||||
let j = i;
|
|
||||||
while (j + 1 < 24 && me[j + 1] >= 2) j++;
|
|
||||||
const L = j - i + 1;
|
|
||||||
if (L >= 2) {
|
|
||||||
// op checkers behind the run: my coordinate k = 23 − jop < i (bar counts)
|
|
||||||
let trapped = op[24];
|
|
||||||
for (let jo = 0; jo < 24; jo++) if (op[jo] && 23 - jo < i) trapped += op[jo];
|
|
||||||
const base = TUNE.prime[Math.min(6, L)];
|
|
||||||
const v = trapped ? base * (1 + TUNE.trappedBonus * Math.min(3, trapped)) : base * 0.25;
|
|
||||||
if (v > best) best = v;
|
|
||||||
}
|
|
||||||
i = j + 1;
|
|
||||||
}
|
|
||||||
return best;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── race ─────────────────────────────────────────────────────────────────────
|
|
||||||
const MU = 8.1667;
|
|
||||||
function raceProb(me, op, useTable) {
|
|
||||||
if (me[25] === 15) return 1;
|
|
||||||
if (op[25] === 15) return 0;
|
|
||||||
if (useTable && canBearOffP(me) && canBearOffP(op) && Bearoff.ready()) {
|
|
||||||
const p = Bearoff.raceWinProb([me[0], me[1], me[2], me[3], me[4], me[5]], [op[0], op[1], op[2], op[3], op[4], op[5]]);
|
|
||||||
if (p !== null) return p;
|
|
||||||
}
|
|
||||||
const pm = pipP(me), po = pipP(op);
|
|
||||||
const waste = (b) => (b[0] * 1.6 + b[1] * 0.9 + b[2] * 0.4) * (canBearOffP(b) ? 1 : 0.4);
|
|
||||||
const em = (pm + waste(me)) / MU, eo = (po + waste(op)) / MU;
|
|
||||||
const sd = Math.max(0.4, Math.sqrt(0.0339 * (pm + po)));
|
|
||||||
return Bearoff.phi((-0.5 - (em - eo)) / sd);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── evaluation ───────────────────────────────────────────────────────────────
|
|
||||||
// mode: 'full' | 'simple'
|
|
||||||
export function evaluate(me, op, mode = 'full') {
|
|
||||||
if (me[25] === 15) return 1;
|
|
||||||
if (op[25] === 15) return 0;
|
|
||||||
if (!hasContact(me, op)) return raceProb(me, op, mode === 'full');
|
|
||||||
return logistic(contactScore(me, op, mode) / TUNE.K);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function contactScore(me, op, mode = 'full') {
|
|
||||||
const T = TUNE;
|
|
||||||
let s = pipP(op) - pipP(me) - T.onRoll;
|
|
||||||
const pv = mode === 'full' ? PV : PV_SIMPLE;
|
|
||||||
const pvk = mode === 'full' ? T.pvScale : 1;
|
|
||||||
for (let i = 0; i < 24; i++) {
|
|
||||||
if (me[i] >= 2) s += pv[i] * pvk;
|
|
||||||
if (op[i] >= 2) s -= pv[i] * pvk;
|
|
||||||
}
|
|
||||||
const hcMe = homeClosed(me), hcOp = homeClosed(op);
|
|
||||||
s += T.barBase * op[24] + T.barHome * hcMe * hcMe * op[24] * 0.5;
|
|
||||||
s -= T.barBase * me[24] + T.barHome * hcOp * hcOp * me[24] * 0.5;
|
|
||||||
|
|
||||||
if (mode === 'full') {
|
|
||||||
s += (primeValue(me, op) - primeValue(op, me)) * T.primeScale;
|
|
||||||
// my blots, op to roll: real risk
|
|
||||||
const sh = shotInfo(me, op);
|
|
||||||
if (sh.blots) {
|
|
||||||
let risk = 0, maxR = 0;
|
|
||||||
for (let i = 0; i < 24; i++) {
|
|
||||||
if (!sh.per[i]) continue;
|
|
||||||
const cost = T.blotBase + T.blotPerPip * (24 - i) + T.blotHome * hcOp;
|
|
||||||
const r = (sh.per[i] / 36) * cost;
|
|
||||||
risk += r;
|
|
||||||
if (r > maxR) maxR = r;
|
|
||||||
}
|
|
||||||
s -= maxR + (risk - maxR) * 0.45;
|
|
||||||
}
|
|
||||||
// op's blots: they move first, so worth much less
|
|
||||||
const sh2 = shotInfo(op, me);
|
|
||||||
if (sh2.blots) {
|
|
||||||
let risk = 0;
|
|
||||||
for (let i = 0; i < 24; i++) {
|
|
||||||
if (!sh2.per[i]) continue;
|
|
||||||
risk += (sh2.per[i] / 36) * (T.blotBase + T.blotPerPip * (24 - i) + T.blotHome * hcMe);
|
|
||||||
}
|
|
||||||
s += risk * T.oppBlotW;
|
|
||||||
}
|
|
||||||
for (let i = 0; i < 24; i++) {
|
|
||||||
if (me[i] > 4) s -= (me[i] - 4) * T.stack;
|
|
||||||
if (op[i] > 4) s += (op[i] - 4) * T.stack;
|
|
||||||
}
|
|
||||||
// back checkers versus a strong home board
|
|
||||||
let backMe = me[24], backOp = op[24];
|
|
||||||
for (let i = 18; i < 24; i++) { backMe += me[i]; backOp += op[i]; }
|
|
||||||
s -= backMe * hcOp * T.backStuck * 0.4;
|
|
||||||
s += backOp * hcMe * T.backStuck * 0.4;
|
|
||||||
} else {
|
|
||||||
// simple: flat blot penalty where an enemy checker is behind it
|
|
||||||
let opBack = -1;
|
|
||||||
for (let j = 24; j >= 0; j--) if (op[j]) { opBack = 23 - j; break; } // lowest my-coordinate of an op checker
|
|
||||||
for (let i = 0; i < 24; i++) if (me[i] === 1 && opBack < i) s -= i < 6 ? 5 : 3;
|
|
||||||
let meBack = -1;
|
|
||||||
for (let j = 24; j >= 0; j--) if (me[j]) { meBack = 23 - j; break; }
|
|
||||||
for (let i = 0; i < 24; i++) if (op[i] === 1 && meBack < i) s += 1;
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
// P(player wins) when it is player's turn to roll (before rolling).
|
|
||||||
export function winProbOnRoll(state, player, mode = 'full') {
|
|
||||||
const { me, op } = boardsFor(state, player);
|
|
||||||
return 1 - evaluate(op, me, mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── turn choice ──────────────────────────────────────────────────────────────
|
|
||||||
export const SKILL = {
|
|
||||||
1: { mode: 'simple', noise: 0.09, loose: 0.25 },
|
|
||||||
2: { mode: 'simple', noise: 0.045, loose: 0.08 },
|
|
||||||
3: { mode: 'simple', noise: 0.012, loose: 0 },
|
|
||||||
4: { mode: 'full', noise: 0, loose: 0 },
|
|
||||||
5: { mode: 'full', noise: 0, loose: 0, ply2: 8, budgetMs: 450 },
|
|
||||||
};
|
|
||||||
|
|
||||||
function gauss(rng) {
|
|
||||||
const u = Math.max(1e-9, rng()), v = rng();
|
|
||||||
return Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
|
|
||||||
}
|
|
||||||
|
|
||||||
function seqToMoves(player, seq) {
|
|
||||||
return seq.map(([from, to, die, hit]) => ({
|
|
||||||
from: from === 24 ? 'bar' : toIdx(player, from),
|
|
||||||
to: to < 0 ? 'off' : toIdx(player, to),
|
|
||||||
dieUsed: die,
|
|
||||||
hit: !!hit,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2-ply: average over the opponent's 21 rolls of (1 − their best reply).
|
|
||||||
function twoPly(meB, opB) {
|
|
||||||
if (!hasContact(meB, opB)) return evaluate(meB, opB, 'full');
|
|
||||||
let sum = 0;
|
|
||||||
for (const { a, b, w } of ROLLS) {
|
|
||||||
const dice = a === b ? [a, a, a, a] : [a, b];
|
|
||||||
const replies = enumerateTurns(opB, meB, dice);
|
|
||||||
let best = 0;
|
|
||||||
for (const r of replies) {
|
|
||||||
const v = evaluate(r.me, r.op, 'full');
|
|
||||||
if (v > best) best = v;
|
|
||||||
if (best > 0.999) break;
|
|
||||||
}
|
|
||||||
sum += w * (1 - best);
|
|
||||||
}
|
|
||||||
return sum / 36;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Choose a full turn. Returns { moves, value, turns } (value = P(win) after it). */
|
|
||||||
export function chooseTurn(state, skill = 3, rng = Math.random) {
|
|
||||||
const player = state.currentPlayer;
|
|
||||||
const { me, op } = boardsFor(state, player);
|
|
||||||
const turns = enumerateTurns(me, op, state.movesLeft);
|
|
||||||
if (turns.length <= 1) {
|
|
||||||
const t = turns[0];
|
|
||||||
return { moves: t ? seqToMoves(player, t.seq) : [], value: t ? evaluate(t.me, t.op) : 0.5, turns: turns.length };
|
|
||||||
}
|
|
||||||
const prof = SKILL[Math.max(1, Math.min(5, Math.round(skill)))];
|
|
||||||
const scored = turns.map((t) => ({ t, v: evaluate(t.me, t.op, prof.mode) }));
|
|
||||||
if (prof.noise) for (const x of scored) x.v += gauss(rng) * prof.noise;
|
|
||||||
scored.sort((x, y) => y.v - x.v);
|
|
||||||
let pick = scored[0];
|
|
||||||
if (prof.loose && rng() < prof.loose) {
|
|
||||||
const k = Math.max(1, Math.ceil(scored.length * 0.5));
|
|
||||||
pick = scored[Math.floor(rng() * k)];
|
|
||||||
}
|
|
||||||
if (prof.ply2 && scored.length > 1) {
|
|
||||||
// candidates in 1-ply order; stop early past the time budget (slow devices)
|
|
||||||
const top = scored.slice(0, prof.ply2);
|
|
||||||
const t0 = now();
|
|
||||||
let best = null;
|
let best = null;
|
||||||
for (const x of top) {
|
let bestScore = -Infinity;
|
||||||
const v = twoPly(x.t.me, x.t.op);
|
for (const seq of sequences) {
|
||||||
if (!best || v > best.v2) best = { ...x, v2: v };
|
const score = evaluateState(seq.finalState, 'black');
|
||||||
if (prof.budgetMs && now() - t0 > prof.budgetMs) break;
|
if (score > bestScore) { bestScore = score; best = seq; }
|
||||||
}
|
}
|
||||||
pick = best;
|
return best ? best.moves : [];
|
||||||
}
|
|
||||||
return { moves: seqToMoves(player, pick.t.seq), value: pick.v2 ?? pick.v, turns: turns.length };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── cube ─────────────────────────────────────────────────────────────────────
|
function generateSequences(state, depth = 0) {
|
||||||
const CUBE_NOISE = { 1: 0.16, 2: 0.1, 3: 0.06, 4: 0.03, 5: 0 };
|
if (depth > 6) return [{ moves: [], finalState: state }];
|
||||||
|
|
||||||
function postCrawfordTrailer(match, player) {
|
const validMoves = getValidMoves(state);
|
||||||
if (!match || match.length <= 0 || !match.hadCrawford || match.crawford) return false;
|
if (validMoves.length === 0 || state.movesLeft.length === 0) {
|
||||||
const opp = other(player);
|
return [{ moves: [], finalState: state }];
|
||||||
return match.score[opp] === match.length - 1 && match.score[player] < match.length - 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Should `player` (on roll, cube available) offer a double? */
|
const results = [];
|
||||||
export function shouldDouble(state, player, skill = 3, match = null, rng = Math.random) {
|
const seenBoards = new Set();
|
||||||
if (!state.cubeEnabled) return false;
|
|
||||||
if (match && match.length > 0) {
|
for (const move of validMoves) {
|
||||||
if (match.score[player] + state.cube.value >= match.length) return false; // dead cube: winning already wins the match
|
const next = applyMove(state, move);
|
||||||
if (postCrawfordTrailer(match, player)) return true;
|
// If applyMove ended the turn, no further moves are possible in this sequence
|
||||||
if (match.score[other(player)] === match.length - 1) return false;
|
const finished = next.currentPlayer !== state.currentPlayer || next.phase !== 'move';
|
||||||
|
if (finished) {
|
||||||
|
results.push({ moves: [move], finalState: next });
|
||||||
|
} else {
|
||||||
|
const subSeqs = generateSequences(next, depth + 1);
|
||||||
|
for (const sub of subSeqs) {
|
||||||
|
const key = boardHash(sub.finalState);
|
||||||
|
if (!seenBoards.has(key)) {
|
||||||
|
seenBoards.add(key);
|
||||||
|
results.push({ moves: [move, ...sub.moves], finalState: sub.finalState });
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const mode = skill >= 4 ? 'full' : 'simple';
|
|
||||||
const p = winProbOnRoll(state, player, mode) + gauss(rng) * (CUBE_NOISE[skill] ?? 0.05);
|
|
||||||
if (skill <= 1 && rng() < 0.5) return false; // a timid beginner
|
|
||||||
// too good to double: play on for the gammon (gammons count unless Jacoby with a centred cube)
|
|
||||||
const gammonsCount = !(state.jacoby && state.cube.value === 1);
|
|
||||||
const tooGood = p > 0.9 && gammonsCount && gammonThreat(state, player);
|
|
||||||
return p >= 0.7 && !tooGood;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Should `taker` accept a double offered by the other player? */
|
return results.length > 0 ? results : [{ moves: [], finalState: state }];
|
||||||
export function shouldTake(state, taker, skill = 3, match = null, rng = Math.random) {
|
|
||||||
const offerer = other(taker);
|
|
||||||
if (match && match.length > 0) {
|
|
||||||
if (match.score[offerer] + state.cube.value >= match.length) return true; // dropping loses the match anyway
|
|
||||||
if (postCrawfordTrailer(match, offerer)) return true;
|
|
||||||
}
|
|
||||||
const mode = skill >= 4 ? 'full' : 'simple';
|
|
||||||
const pTaker = 1 - winProbOnRoll(state, offerer, mode) + gauss(rng) * (CUBE_NOISE[skill] ?? 0.05);
|
|
||||||
return pTaker >= 0.25;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function gammonThreat(state, player) {
|
function boardHash(state) {
|
||||||
const { me, op } = boardsFor(state, player);
|
return state.points.map((p) => `${p.color?.[0] ?? '-'}${p.count}`).join('') +
|
||||||
if (op[25] > 0) return false;
|
`|b${state.bar.black}w${state.bar.white}`;
|
||||||
// opponent still has 3+ checkers back in my home board / on the bar and trails badly
|
|
||||||
let back = op[24];
|
|
||||||
for (let i = 18; i < 24; i++) back += op[i];
|
|
||||||
return back >= 3 && pipP(op) - pipP(me) > 50;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── coaching ─────────────────────────────────────────────────────────────────
|
function evaluateState(state, player) {
|
||||||
const pointName = (i) => (i === 6 ? 'bar point' : `${i + 1}-point`);
|
const opp = player === 'white' ? 'black' : 'white';
|
||||||
|
let score = 0;
|
||||||
|
|
||||||
/** Plain-English reason for a turn played from `state`. */
|
// Pip count advantage
|
||||||
export function explainTurn(state, moves) {
|
const ownPips = computePipCount(state, player);
|
||||||
const player = state.currentPlayer;
|
const oppPips = computePipCount(state, opp);
|
||||||
const before = boardsFor(state, player);
|
score += (oppPips - ownPips) * 1.5;
|
||||||
let me = before.me.slice(), op = before.op.slice();
|
|
||||||
let hits = 0, off = 0, entered = 0;
|
// Borne off bonus
|
||||||
for (const m of moves) {
|
score += state.borneOff[player] * 25;
|
||||||
const from = m.from === 'bar' ? 24 : (player === WHITE ? m.from : 23 - m.from);
|
score -= state.borneOff[opp] * 25;
|
||||||
const to = m.to === 'off' ? -1 : (player === WHITE ? m.to : 23 - m.to);
|
|
||||||
if (from === 24) entered++;
|
// Opponent checkers on bar (we sent them there)
|
||||||
if (to < 0) off++;
|
score += state.bar[opp] * 20;
|
||||||
me[from]--;
|
|
||||||
if (to >= 0) { me[to]++; const j = 23 - to; if (op[j] === 1) { op[j] = 0; op[24]++; hits++; } }
|
// Own blots (lone exposed checkers)
|
||||||
else me[25]++;
|
for (let i = 0; i < 24; i++) {
|
||||||
|
const pt = state.points[i];
|
||||||
|
if (pt.color === player && pt.count === 1) score -= 8;
|
||||||
|
if (pt.color === player && pt.count >= 2) {
|
||||||
|
// Home board anchors
|
||||||
|
const inHome = player === 'white' ? (i <= 5) : (i >= 18);
|
||||||
|
if (inHome) score += 10;
|
||||||
}
|
}
|
||||||
const bits = [];
|
|
||||||
if (hits) bits.push(hits > 1 ? `hits ${hits} blots` : 'hits a blot');
|
|
||||||
if (entered) bits.push(entered > 1 ? `enters ${entered} from the bar` : 'enters from the bar');
|
|
||||||
const made = [];
|
|
||||||
for (let i = 0; i < 24; i++) if (me[i] >= 2 && before.me[i] < 2) made.push(i);
|
|
||||||
if (made.length) {
|
|
||||||
const named = made.filter((i) => i <= 6 || i >= 18).map((i) => (i >= 18 ? `an anchor on the ${i + 1}-point` : `your ${pointName(i)}`));
|
|
||||||
if (named.length) bits.push(`makes ${named.slice(0, 2).join(' and ')}`);
|
|
||||||
else bits.push(made.length > 1 ? `makes ${made.length} points` : 'makes a point');
|
|
||||||
}
|
|
||||||
if (off) bits.push(off > 1 ? `bears off ${off}` : 'bears one off');
|
|
||||||
if (hasContact(me, op)) {
|
|
||||||
const sh = shotInfo(me, op);
|
|
||||||
if (!sh.blots || !sh.union) bits.push('leaves no shots');
|
|
||||||
else bits.push(`leaves ${sh.union} shot${sh.union === 1 ? '' : 's'} (${Math.round((sh.union / 36) * 100)}%)`);
|
|
||||||
} else if (!bits.length) bits.push('races safely home');
|
|
||||||
let s = bits.join(' · ');
|
|
||||||
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Best turn from the current position (skill-5 search) plus its reason. */
|
// Prime bonus — runs of 3+ consecutive blocked points
|
||||||
export function hint(state) {
|
let run = 0;
|
||||||
const r = chooseTurn(state, 5, () => 0.5);
|
for (let i = 0; i < 24; i++) {
|
||||||
return { moves: r.moves, reason: r.moves.length ? explainTurn(state, r.moves) : 'No legal move', value: r.value };
|
if (state.points[i].color === player && state.points[i].count >= 2) {
|
||||||
|
run++;
|
||||||
|
if (run >= 3) score += 15;
|
||||||
|
} else {
|
||||||
|
run = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Bearoff };
|
return score;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,764 +0,0 @@
|
||||||
// BackgammonArt.js — baked canvas textures for "Tavli at the seaside kafeneio".
|
|
||||||
// All procedural: no image files.
|
|
||||||
//
|
|
||||||
// bg-room sun-warmed, blue-painted café table (worn to the wood),
|
|
||||||
// tea glass + saucer, komboloi beads over the table edge
|
|
||||||
// bg-vignette sun + vignette overlay for a chosen playfield tablecloth
|
|
||||||
// bg-props tea glass, beads and leaves alone (drawn over a playfield)
|
|
||||||
// bg-case the open olive-wood tavli case: Greek-key inlay, mother-of-
|
|
||||||
// pearl rosettes, teal leather fields, bone/oxblood points,
|
|
||||||
// hinge with brass knuckles, grooved bear-off tray
|
|
||||||
// bg-chk-<c> turned checkers (white = bone, black = walnut)
|
|
||||||
// bg-edge-<c> a borne-off checker standing on edge in the tray
|
|
||||||
// bg-chk-shadow soft contact shadow
|
|
||||||
// bg-glow soft gold ring (selection / movable)
|
|
||||||
// bg-cup-<c> stitched leather dice cups (honey for you, oxblood for them)
|
|
||||||
// bg-cube-<v> doubling-cube faces 64 / 2 / 4 / 8 / 16 / 32
|
|
||||||
// bg-plate a whitewashed board with blue trim (player plates)
|
|
||||||
// bg-slate the café chalk slate
|
|
||||||
// bg-ledger a waiter's order pad (move ledger)
|
|
||||||
// bg-slip a torn paper slip (cube offers)
|
|
||||||
// bg-dapple drifting vine-leaf shadows
|
|
||||||
// bg-spark / bg-steam
|
|
||||||
|
|
||||||
import { canvas, rr, noisePattern } from '../../ui/casino/CasinoArt.js';
|
|
||||||
import {
|
|
||||||
W, H, CASE, FRAME, FY, FH, PW, PH, CR, HALF_W, BAR_W, TRAY_W, MID_Y,
|
|
||||||
OPP_PLATE, SLATE, TEA, LEDGER, BEADS, AI_CUP,
|
|
||||||
} from './BackgammonLayout.js';
|
|
||||||
|
|
||||||
export const DISPLAY_FONT = 'Righteous, Georgia, serif';
|
|
||||||
export const SERIF = 'Georgia, "Times New Roman", serif';
|
|
||||||
export const HAND_FONT = 'YummyCupcakes, "Comic Sans MS", cursive';
|
|
||||||
export const PRINT_FONT = '"Julius Sans One", Georgia, serif';
|
|
||||||
export const CASE_PAD = 34;
|
|
||||||
export const CUBE_VALUES = [64, 2, 4, 8, 16, 32];
|
|
||||||
export const CHK = { size: CR * 2 + 14, edgeW: CR * 2 + 8, edgeH: 13 };
|
|
||||||
export const INK = { white: '#2a3f66', black: '#7a2420' };
|
|
||||||
export const TINT = { white: 0xe9dcc0, black: 0x5a3422 };
|
|
||||||
|
|
||||||
function addCanvas(scene, key, c) {
|
|
||||||
if (scene.textures.exists(key)) scene.textures.remove(key);
|
|
||||||
scene.textures.addCanvas(key, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
function shade(hex, k) {
|
|
||||||
const n = parseInt(hex.slice(1), 16);
|
|
||||||
const c = [n >> 16, (n >> 8) & 255, n & 255].map((v) => Math.max(0, Math.min(255, Math.round(v * k))));
|
|
||||||
return `rgb(${c[0]},${c[1]},${c[2]})`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// seeded so the room looks the same every visit
|
|
||||||
function seeded(seed) {
|
|
||||||
let a = seed >>> 0;
|
|
||||||
return () => {
|
|
||||||
a = (a + 0x6d2b79f5) >>> 0;
|
|
||||||
let t = a;
|
|
||||||
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
||||||
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
||||||
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function grain(ctx, rnd, x, y, w, h, { tone = 'rgba(60,32,10,0.22)', lines = 14, wave = 3, vertical = false } = {}) {
|
|
||||||
ctx.save();
|
|
||||||
ctx.beginPath(); ctx.rect(x, y, w, h); ctx.clip();
|
|
||||||
ctx.strokeStyle = tone;
|
|
||||||
const L = vertical ? h : w;
|
|
||||||
const S = vertical ? w : h;
|
|
||||||
for (let i = 0; i < lines; i++) {
|
|
||||||
const o = rnd() * S;
|
|
||||||
const amp = wave * (0.4 + rnd());
|
|
||||||
const f = 0.004 + rnd() * 0.012;
|
|
||||||
const ph = rnd() * 6;
|
|
||||||
ctx.lineWidth = 0.6 + rnd() * 1.6;
|
|
||||||
ctx.beginPath();
|
|
||||||
for (let t = 0; t <= L; t += 6) {
|
|
||||||
const d = o + Math.sin(t * f + ph) * amp + Math.sin(t * f * 3.1 + ph) * amp * 0.3;
|
|
||||||
const px = vertical ? x + d : x + t, py = vertical ? y + t : y + d;
|
|
||||||
if (t === 0) ctx.moveTo(px, py); else ctx.lineTo(px, py);
|
|
||||||
}
|
|
||||||
ctx.stroke();
|
|
||||||
}
|
|
||||||
ctx.restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Olive wood: pale honey with bold dark swirls.
|
|
||||||
function oliveWood(ctx, rnd, x, y, w, h, vertical = false) {
|
|
||||||
const g = vertical ? ctx.createLinearGradient(x, 0, x + w, 0) : ctx.createLinearGradient(0, y, 0, y + h);
|
|
||||||
g.addColorStop(0, '#c89a5c'); g.addColorStop(0.5, '#d9b277'); g.addColorStop(1, '#b8874a');
|
|
||||||
ctx.fillStyle = g;
|
|
||||||
ctx.fillRect(x, y, w, h);
|
|
||||||
grain(ctx, rnd, x, y, w, h, { tone: 'rgba(92,52,18,0.30)', lines: Math.max(6, (vertical ? w : h) / 3), wave: 6, vertical });
|
|
||||||
grain(ctx, rnd, x, y, w, h, { tone: 'rgba(60,30,8,0.45)', lines: Math.max(2, (vertical ? w : h) / 14), wave: 14, vertical });
|
|
||||||
ctx.fillStyle = noisePattern(ctx, 64, 22);
|
|
||||||
ctx.fillRect(x, y, w, h);
|
|
||||||
}
|
|
||||||
|
|
||||||
function dropShadow(ctx, fn, { blur = 26, dx = 10, dy = 14, alpha = 0.5 } = {}) {
|
|
||||||
ctx.save();
|
|
||||||
ctx.shadowColor = `rgba(10,20,30,${alpha})`;
|
|
||||||
ctx.shadowBlur = blur; ctx.shadowOffsetX = dx; ctx.shadowOffsetY = dy;
|
|
||||||
fn();
|
|
||||||
ctx.restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── room ─────────────────────────────────────────────────────────────────────
|
|
||||||
function paintTable(ctx, rnd, w, h) {
|
|
||||||
// planks of wood under worn Aegean-blue paint
|
|
||||||
const plankH = 120;
|
|
||||||
const tones = ['#8a6238', '#7d5732', '#94693d', '#83603a'];
|
|
||||||
for (let py = 0, i = 0; py < h; py += plankH, i++) {
|
|
||||||
const ph = Math.min(plankH, h - py);
|
|
||||||
ctx.fillStyle = tones[i % tones.length];
|
|
||||||
ctx.fillRect(0, py, w, ph);
|
|
||||||
grain(ctx, rnd, 0, py, w, ph, { lines: 20, tone: 'rgba(50,28,8,0.3)' });
|
|
||||||
}
|
|
||||||
const paint = canvas(w, h), pc = paint.getContext('2d');
|
|
||||||
const pg = pc.createLinearGradient(0, 0, w, h);
|
|
||||||
pg.addColorStop(0, '#5b9ccc'); pg.addColorStop(0.55, '#4a87b8'); pg.addColorStop(1, '#3d76a6');
|
|
||||||
pc.fillStyle = pg;
|
|
||||||
pc.fillRect(0, 0, w, h);
|
|
||||||
// brush streaks
|
|
||||||
for (let i = 0; i < 260; i++) {
|
|
||||||
pc.strokeStyle = rnd() < 0.5 ? 'rgba(255,255,255,0.05)' : 'rgba(10,40,70,0.06)';
|
|
||||||
pc.lineWidth = 2 + rnd() * 6;
|
|
||||||
const y = rnd() * h;
|
|
||||||
pc.beginPath(); pc.moveTo(rnd() * w, y); pc.lineTo(rnd() * w, y + (rnd() - 0.5) * 6); pc.stroke();
|
|
||||||
}
|
|
||||||
// wear: chipped patches showing the wood (and white undercoat at the rim)
|
|
||||||
pc.globalCompositeOperation = 'destination-out';
|
|
||||||
for (let i = 0; i < 110; i++) {
|
|
||||||
const x = rnd() * w, y = rnd() * h;
|
|
||||||
const r = 6 + rnd() * 34;
|
|
||||||
pc.fillStyle = `rgba(0,0,0,${0.5 + rnd() * 0.5})`;
|
|
||||||
pc.beginPath();
|
|
||||||
for (let k = 0; k < 9; k++) {
|
|
||||||
const a = (k / 9) * Math.PI * 2, rr2 = r * (0.5 + rnd() * 0.7);
|
|
||||||
const px = x + Math.cos(a) * rr2 * 1.8, py = y + Math.sin(a) * rr2 * 0.6;
|
|
||||||
if (k) pc.lineTo(px, py); else pc.moveTo(px, py);
|
|
||||||
}
|
|
||||||
pc.closePath(); pc.fill();
|
|
||||||
}
|
|
||||||
// plank edges rub through most
|
|
||||||
for (let py = plankH; py < h; py += plankH) {
|
|
||||||
for (let x = 0; x < w; x += 18) {
|
|
||||||
if (rnd() < 0.55) { pc.fillStyle = `rgba(0,0,0,${0.4 + rnd() * 0.6})`; pc.fillRect(x, py - 3 - rnd() * 4, 12 + rnd() * 26, 5 + rnd() * 6); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pc.globalCompositeOperation = 'source-over';
|
|
||||||
ctx.drawImage(paint, 0, 0);
|
|
||||||
// plank seams
|
|
||||||
for (let py = plankH; py < h; py += plankH) {
|
|
||||||
ctx.fillStyle = 'rgba(20,20,30,0.55)'; ctx.fillRect(0, py - 1, w, 3);
|
|
||||||
ctx.fillStyle = 'rgba(255,255,255,0.08)'; ctx.fillRect(0, py + 2, w, 1);
|
|
||||||
}
|
|
||||||
ctx.fillStyle = noisePattern(ctx, 96, 26);
|
|
||||||
ctx.fillRect(0, 0, w, h);
|
|
||||||
}
|
|
||||||
|
|
||||||
function sunAndVignette(ctx, w, h) {
|
|
||||||
const g = ctx.createRadialGradient(w * 0.32, h * 0.1, 40, w * 0.4, h * 0.3, w * 0.85);
|
|
||||||
g.addColorStop(0, 'rgba(255,232,170,0.28)');
|
|
||||||
g.addColorStop(0.5, 'rgba(255,214,140,0.08)');
|
|
||||||
g.addColorStop(1, 'rgba(0,0,0,0)');
|
|
||||||
ctx.fillStyle = g; ctx.fillRect(0, 0, w, h);
|
|
||||||
const v = ctx.createRadialGradient(w / 2, h / 2, h * 0.45, w / 2, h / 2, h * 1.05);
|
|
||||||
v.addColorStop(0, 'rgba(0,0,0,0)'); v.addColorStop(1, 'rgba(8,16,28,0.55)');
|
|
||||||
ctx.fillStyle = v; ctx.fillRect(0, 0, w, h);
|
|
||||||
}
|
|
||||||
|
|
||||||
function teaGlass(ctx, cx, cy) {
|
|
||||||
// saucer (white with a blue rim) seen from above, slight perspective
|
|
||||||
dropShadow(ctx, () => {
|
|
||||||
ctx.fillStyle = '#f4f1ea';
|
|
||||||
ctx.beginPath(); ctx.ellipse(cx, cy, 64, 46, 0, 0, Math.PI * 2); ctx.fill();
|
|
||||||
}, { blur: 14, dx: 6, dy: 8, alpha: 0.45 });
|
|
||||||
ctx.strokeStyle = '#2f5f9a'; ctx.lineWidth = 4;
|
|
||||||
ctx.beginPath(); ctx.ellipse(cx, cy, 58, 41, 0, 0, Math.PI * 2); ctx.stroke();
|
|
||||||
ctx.strokeStyle = 'rgba(47,95,154,0.5)'; ctx.lineWidth = 1.5;
|
|
||||||
ctx.beginPath(); ctx.ellipse(cx, cy, 50, 35, 0, 0, Math.PI * 2); ctx.stroke();
|
|
||||||
// two sugar cubes
|
|
||||||
for (const [dx, dy, a] of [[-40, 14, 0.3], [-26, 24, -0.2]]) {
|
|
||||||
ctx.save(); ctx.translate(cx + dx, cy + dy); ctx.rotate(a);
|
|
||||||
ctx.fillStyle = '#fffdf6'; ctx.fillRect(-7, -7, 14, 14);
|
|
||||||
ctx.fillStyle = 'rgba(0,0,0,0.12)'; ctx.fillRect(-7, 4, 14, 3);
|
|
||||||
ctx.restore();
|
|
||||||
}
|
|
||||||
// tulip tea glass: base ring, amber tea, rim highlight
|
|
||||||
ctx.fillStyle = 'rgba(0,0,0,0.25)';
|
|
||||||
ctx.beginPath(); ctx.ellipse(cx + 12, cy - 2, 28, 22, 0, 0, Math.PI * 2); ctx.fill();
|
|
||||||
const tea = ctx.createRadialGradient(cx + 2, cy - 10, 4, cx + 8, cy - 6, 30);
|
|
||||||
tea.addColorStop(0, '#e2902c'); tea.addColorStop(0.6, '#b05a14'); tea.addColorStop(1, '#6e2f08');
|
|
||||||
ctx.fillStyle = tea;
|
|
||||||
ctx.beginPath(); ctx.ellipse(cx + 8, cy - 8, 27, 21, 0, 0, Math.PI * 2); ctx.fill();
|
|
||||||
ctx.strokeStyle = 'rgba(255,255,255,0.75)'; ctx.lineWidth = 2.5;
|
|
||||||
ctx.beginPath(); ctx.ellipse(cx + 8, cy - 8, 29, 23, 0, 0, Math.PI * 2); ctx.stroke();
|
|
||||||
ctx.strokeStyle = 'rgba(255,255,255,0.5)'; ctx.lineWidth = 3;
|
|
||||||
ctx.beginPath(); ctx.ellipse(cx + 8, cy - 8, 22, 16, 0, Math.PI * 1.1, Math.PI * 1.55); ctx.stroke();
|
|
||||||
// a spoon resting on the saucer
|
|
||||||
ctx.save(); ctx.translate(cx + 44, cy + 16); ctx.rotate(-0.5);
|
|
||||||
ctx.fillStyle = '#c9ccd2';
|
|
||||||
ctx.beginPath(); ctx.ellipse(0, 0, 9, 6, 0, 0, Math.PI * 2); ctx.fill();
|
|
||||||
ctx.fillRect(6, -1.5, 34, 3);
|
|
||||||
ctx.fillStyle = 'rgba(255,255,255,0.6)'; ctx.fillRect(8, -1.5, 28, 1);
|
|
||||||
ctx.restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
function komboloi(ctx, rnd, x0, y0, w) {
|
|
||||||
// a loop of amber beads draped over the table edge, tassel hanging off
|
|
||||||
const beads = [];
|
|
||||||
const n = 19;
|
|
||||||
for (let i = 0; i < n; i++) {
|
|
||||||
const t = i / (n - 1);
|
|
||||||
beads.push({ x: x0 + 20 + t * (w - 70), y: y0 + 8 + Math.sin(t * Math.PI) * 22 + (rnd() - 0.5) * 3 });
|
|
||||||
}
|
|
||||||
ctx.strokeStyle = 'rgba(60,20,8,0.8)'; ctx.lineWidth = 1.5;
|
|
||||||
ctx.beginPath(); beads.forEach((b, i) => (i ? ctx.lineTo(b.x, b.y) : ctx.moveTo(b.x, b.y))); ctx.stroke();
|
|
||||||
for (const b of beads) {
|
|
||||||
ctx.fillStyle = 'rgba(0,0,0,0.3)';
|
|
||||||
ctx.beginPath(); ctx.arc(b.x + 3, b.y + 4, 8, 0, Math.PI * 2); ctx.fill();
|
|
||||||
const g = ctx.createRadialGradient(b.x - 3, b.y - 3, 1, b.x, b.y, 9);
|
|
||||||
g.addColorStop(0, '#ffd27a'); g.addColorStop(0.5, '#d98a1e'); g.addColorStop(1, '#8a4208');
|
|
||||||
ctx.fillStyle = g;
|
|
||||||
ctx.beginPath(); ctx.arc(b.x, b.y, 8, 0, Math.PI * 2); ctx.fill();
|
|
||||||
}
|
|
||||||
// shield bead + tassel
|
|
||||||
const e = beads[beads.length - 1];
|
|
||||||
ctx.fillStyle = '#c9a24a';
|
|
||||||
ctx.beginPath(); ctx.ellipse(e.x + 22, e.y + 4, 9, 6, 0.4, 0, Math.PI * 2); ctx.fill();
|
|
||||||
ctx.strokeStyle = '#7a1e18'; ctx.lineWidth = 1.6;
|
|
||||||
for (let k = 0; k < 9; k++) {
|
|
||||||
ctx.beginPath(); ctx.moveTo(e.x + 28, e.y + 8);
|
|
||||||
ctx.quadraticCurveTo(e.x + 40 + k, e.y + 20, e.x + 34 + k * 2.4, e.y + 40);
|
|
||||||
ctx.stroke();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function bakeRoom(scene) {
|
|
||||||
const rnd = seeded(91);
|
|
||||||
const c = canvas(W, H), ctx = c.getContext('2d');
|
|
||||||
paintTable(ctx, rnd, W, H);
|
|
||||||
teaGlass(ctx, TEA.x + TEA.w / 2, TEA.y + TEA.h / 2);
|
|
||||||
komboloi(ctx, rnd, BEADS.x, BEADS.y, BEADS.w);
|
|
||||||
// a few fallen olive leaves
|
|
||||||
for (const [x, y, a] of [[1660, 640, 0.6], [1890, 820, -0.4], [300, 1060, 1.2], [14, 520, -1.0]]) leaf(ctx, x, y, a, 1);
|
|
||||||
sunAndVignette(ctx, W, H);
|
|
||||||
addCanvas(scene, 'bg-room', c);
|
|
||||||
|
|
||||||
const v = canvas(W, H), vx = v.getContext('2d');
|
|
||||||
sunAndVignette(vx, W, H);
|
|
||||||
addCanvas(scene, 'bg-vignette', v);
|
|
||||||
|
|
||||||
// the props alone, for when a chosen playfield is the tablecloth
|
|
||||||
const p = canvas(W, H), px = p.getContext('2d');
|
|
||||||
const r2 = seeded(91);
|
|
||||||
teaGlass(px, TEA.x + TEA.w / 2, TEA.y + TEA.h / 2);
|
|
||||||
komboloi(px, r2, BEADS.x, BEADS.y, BEADS.w);
|
|
||||||
for (const [x, y, a] of [[1660, 640, 0.6], [1890, 820, -0.4], [300, 1060, 1.2], [14, 520, -1.0]]) leaf(px, x, y, a, 1);
|
|
||||||
addCanvas(scene, 'bg-props', p);
|
|
||||||
}
|
|
||||||
|
|
||||||
function leaf(ctx, x, y, a, alpha = 1, len = 26) {
|
|
||||||
ctx.save(); ctx.translate(x, y); ctx.rotate(a);
|
|
||||||
ctx.globalAlpha = alpha;
|
|
||||||
ctx.fillStyle = 'rgba(0,0,0,0.25)';
|
|
||||||
ctx.beginPath(); ctx.ellipse(3, 4, len, len * 0.28, 0, 0, Math.PI * 2); ctx.fill();
|
|
||||||
const g = ctx.createLinearGradient(0, -8, 0, 8);
|
|
||||||
g.addColorStop(0, '#7c8a4a'); g.addColorStop(1, '#4f5c2c');
|
|
||||||
ctx.fillStyle = g;
|
|
||||||
ctx.beginPath(); ctx.ellipse(0, 0, len, len * 0.28, 0, 0, Math.PI * 2); ctx.fill();
|
|
||||||
ctx.strokeStyle = 'rgba(220,230,180,0.5)'; ctx.lineWidth = 1;
|
|
||||||
ctx.beginPath(); ctx.moveTo(-len, 0); ctx.lineTo(len, 0); ctx.stroke();
|
|
||||||
ctx.restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── the case ─────────────────────────────────────────────────────────────────
|
|
||||||
function greekKey(ctx, x, y, w, h, vertical) {
|
|
||||||
// a running meander in bone on a walnut strip
|
|
||||||
ctx.fillStyle = '#3a2210';
|
|
||||||
ctx.fillRect(x, y, w, h);
|
|
||||||
ctx.strokeStyle = '#ead9b4';
|
|
||||||
ctx.lineWidth = 1.6;
|
|
||||||
const u = vertical ? w : h; // module size
|
|
||||||
const s = u - 3;
|
|
||||||
const L = vertical ? h : w;
|
|
||||||
ctx.beginPath();
|
|
||||||
for (let t = 0; t + u <= L; t += u) {
|
|
||||||
// one meander unit drawn in local coords (along, across)
|
|
||||||
const pts = [[0, s], [0, 1.5], [s * 0.8, 1.5], [s * 0.8, s * 0.65], [s * 0.35, s * 0.65], [s * 0.35, s * 0.4], [s * 0.55, s * 0.4]];
|
|
||||||
pts.forEach(([a, b], i) => {
|
|
||||||
const px = vertical ? x + 1.5 + b : x + t + a + 1;
|
|
||||||
const py = vertical ? y + t + a + 1 : y + 1.5 + b;
|
|
||||||
if (i) ctx.lineTo(px, py); else ctx.moveTo(px, py);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
ctx.stroke();
|
|
||||||
}
|
|
||||||
|
|
||||||
function rosette(ctx, cx, cy, r) {
|
|
||||||
const g = ctx.createRadialGradient(cx - r * 0.3, cy - r * 0.3, 1, cx, cy, r);
|
|
||||||
g.addColorStop(0, '#ffffff'); g.addColorStop(0.35, '#dfe9f2'); g.addColorStop(0.6, '#f2dfe8'); g.addColorStop(0.8, '#d6efe4'); g.addColorStop(1, '#b9c6cf');
|
|
||||||
for (let k = 0; k < 8; k++) {
|
|
||||||
const a = (k / 8) * Math.PI * 2;
|
|
||||||
ctx.save(); ctx.translate(cx, cy); ctx.rotate(a);
|
|
||||||
ctx.fillStyle = g;
|
|
||||||
ctx.beginPath(); ctx.ellipse(r * 0.5, 0, r * 0.5, r * 0.2, 0, 0, Math.PI * 2); ctx.fill();
|
|
||||||
ctx.restore();
|
|
||||||
}
|
|
||||||
ctx.fillStyle = '#c9a24a';
|
|
||||||
ctx.beginPath(); ctx.arc(cx, cy, r * 0.18, 0, Math.PI * 2); ctx.fill();
|
|
||||||
}
|
|
||||||
|
|
||||||
function leather(ctx, x, y, w, h) {
|
|
||||||
const g = ctx.createLinearGradient(0, y, 0, y + h);
|
|
||||||
g.addColorStop(0, '#1d4b47'); g.addColorStop(0.5, '#215550'); g.addColorStop(1, '#1a4440');
|
|
||||||
ctx.fillStyle = g;
|
|
||||||
ctx.fillRect(x, y, w, h);
|
|
||||||
ctx.fillStyle = noisePattern(ctx, 80, 34);
|
|
||||||
ctx.fillRect(x, y, w, h);
|
|
||||||
// stitched border
|
|
||||||
ctx.save();
|
|
||||||
ctx.setLineDash([7, 6]);
|
|
||||||
ctx.strokeStyle = 'rgba(230,214,170,0.45)'; ctx.lineWidth = 1.5;
|
|
||||||
ctx.strokeRect(x + 7, y + 7, w - 14, h - 14);
|
|
||||||
ctx.restore();
|
|
||||||
// inner bevel
|
|
||||||
ctx.strokeStyle = 'rgba(0,0,0,0.45)'; ctx.lineWidth = 4;
|
|
||||||
ctx.strokeRect(x + 2, y + 2, w - 4, h - 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
function point(ctx, ax, bx, baseY, tipY, light) {
|
|
||||||
const cx = (ax + bx) / 2;
|
|
||||||
const base = light ? '#ecdfc0' : '#7d2a22';
|
|
||||||
const g = ctx.createLinearGradient(0, baseY, 0, tipY);
|
|
||||||
g.addColorStop(0, light ? '#efe3c6' : '#86302a');
|
|
||||||
g.addColorStop(1, light ? '#cfbd94' : '#5a1c16');
|
|
||||||
ctx.fillStyle = g;
|
|
||||||
ctx.beginPath(); ctx.moveTo(ax + 2, baseY); ctx.lineTo(bx - 2, baseY); ctx.lineTo(cx, tipY); ctx.closePath(); ctx.fill();
|
|
||||||
// inlay grain
|
|
||||||
ctx.save(); ctx.clip();
|
|
||||||
ctx.strokeStyle = light ? 'rgba(120,90,40,0.18)' : 'rgba(0,0,0,0.22)';
|
|
||||||
ctx.lineWidth = 1;
|
|
||||||
for (let k = 0; k < 7; k++) {
|
|
||||||
const xx = ax + 8 + k * ((bx - ax - 16) / 6);
|
|
||||||
ctx.beginPath(); ctx.moveTo(xx, baseY); ctx.lineTo(cx + (xx - cx) * 0.1, tipY); ctx.stroke();
|
|
||||||
}
|
|
||||||
ctx.restore();
|
|
||||||
// stringing: a fine inset line in the contrasting wood
|
|
||||||
const inset = 7;
|
|
||||||
const dir = tipY < baseY ? -1 : 1;
|
|
||||||
ctx.strokeStyle = light ? 'rgba(90,40,20,0.55)' : 'rgba(240,222,180,0.6)';
|
|
||||||
ctx.lineWidth = 1.2;
|
|
||||||
ctx.beginPath();
|
|
||||||
ctx.moveTo(ax + inset, baseY + dir * 4);
|
|
||||||
ctx.lineTo(bx - inset, baseY + dir * 4);
|
|
||||||
ctx.lineTo(cx, tipY - dir * 16);
|
|
||||||
ctx.closePath(); ctx.stroke();
|
|
||||||
ctx.strokeStyle = 'rgba(0,0,0,0.35)'; ctx.lineWidth = 1;
|
|
||||||
ctx.beginPath(); ctx.moveTo(ax + 2, baseY); ctx.lineTo(cx, tipY); ctx.lineTo(bx - 2, baseY); ctx.stroke();
|
|
||||||
void base;
|
|
||||||
}
|
|
||||||
|
|
||||||
function brassPlate(ctx, x, y, w, h) {
|
|
||||||
const g = ctx.createLinearGradient(x, y, x + w, y + h);
|
|
||||||
g.addColorStop(0, '#f3d98a'); g.addColorStop(0.5, '#c79a3a'); g.addColorStop(1, '#8e6a22');
|
|
||||||
ctx.fillStyle = g;
|
|
||||||
rr(ctx, x, y, w, h, 3); ctx.fill();
|
|
||||||
ctx.strokeStyle = 'rgba(60,40,10,0.7)'; ctx.lineWidth = 1; ctx.stroke();
|
|
||||||
}
|
|
||||||
|
|
||||||
function screw(ctx, x, y) {
|
|
||||||
ctx.fillStyle = '#7a5a1c';
|
|
||||||
ctx.beginPath(); ctx.arc(x, y, 2.6, 0, Math.PI * 2); ctx.fill();
|
|
||||||
ctx.strokeStyle = '#f6e3a8'; ctx.lineWidth = 0.8;
|
|
||||||
ctx.beginPath(); ctx.moveTo(x - 2, y); ctx.lineTo(x + 2, y); ctx.stroke();
|
|
||||||
}
|
|
||||||
|
|
||||||
function bakeCase(scene) {
|
|
||||||
const rnd = seeded(7);
|
|
||||||
const P = CASE_PAD;
|
|
||||||
const c = canvas(CASE.w + P * 2, CASE.h + P * 2), ctx = c.getContext('2d');
|
|
||||||
const X = (x) => x - CASE.x + P, Y = (y) => y - CASE.y + P;
|
|
||||||
const x0 = P, y0 = P, w = CASE.w, h = CASE.h;
|
|
||||||
|
|
||||||
dropShadow(ctx, () => { ctx.fillStyle = '#6b4a22'; rr(ctx, x0, y0, w, h, 14); ctx.fill(); }, { blur: 34, dx: 14, dy: 20, alpha: 0.6 });
|
|
||||||
ctx.save(); rr(ctx, x0, y0, w, h, 14); ctx.clip();
|
|
||||||
oliveWood(ctx, rnd, x0, y0, w, h);
|
|
||||||
ctx.restore();
|
|
||||||
// outer bevel
|
|
||||||
ctx.strokeStyle = 'rgba(255,240,200,0.35)'; ctx.lineWidth = 2; rr(ctx, x0 + 2, y0 + 2, w - 4, h - 4, 12); ctx.stroke();
|
|
||||||
ctx.strokeStyle = 'rgba(40,20,5,0.6)'; ctx.lineWidth = 2; rr(ctx, x0 + 1, y0 + 1, w - 2, h - 2, 13); ctx.stroke();
|
|
||||||
|
|
||||||
const leftX = CASE.x + FRAME, barX = leftX + HALF_W, rightX = barX + BAR_W, trayX = rightX + HALF_W + FRAME;
|
|
||||||
// Greek-key bands along the outer frame (top and bottom), between the rails
|
|
||||||
const band = 12;
|
|
||||||
greekKey(ctx, X(leftX), Y(CASE.y) + (FRAME - band) / 2, HALF_W * 2 + BAR_W, band, false);
|
|
||||||
greekKey(ctx, X(leftX), Y(CASE.y + CASE.h - FRAME) + (FRAME - band) / 2, HALF_W * 2 + BAR_W, band, false);
|
|
||||||
// rosettes at the four frame corners
|
|
||||||
for (const [x, y] of [[CASE.x + FRAME / 2, CASE.y + FRAME / 2], [CASE.x + CASE.w - FRAME / 2, CASE.y + FRAME / 2], [CASE.x + FRAME / 2, CASE.y + CASE.h - FRAME / 2], [CASE.x + CASE.w - FRAME / 2, CASE.y + CASE.h - FRAME / 2]]) {
|
|
||||||
rosette(ctx, X(x), Y(y), 12);
|
|
||||||
}
|
|
||||||
// brass corner guards
|
|
||||||
for (const [x, y, sx, sy] of [[x0, y0, 1, 1], [x0 + w, y0, -1, 1], [x0, y0 + h, 1, -1], [x0 + w, y0 + h, -1, -1]]) {
|
|
||||||
ctx.save(); ctx.translate(x, y); ctx.scale(sx, sy);
|
|
||||||
const g = ctx.createLinearGradient(0, 0, 40, 40);
|
|
||||||
g.addColorStop(0, '#f3d98a'); g.addColorStop(1, '#8e6a22');
|
|
||||||
ctx.fillStyle = g;
|
|
||||||
ctx.beginPath(); ctx.moveTo(0, 14); ctx.quadraticCurveTo(0, 0, 14, 0); ctx.lineTo(44, 0); ctx.lineTo(44, 7); ctx.lineTo(7, 7); ctx.lineTo(7, 44); ctx.lineTo(0, 44); ctx.closePath(); ctx.fill();
|
|
||||||
screw(ctx, 24, 3.5); screw(ctx, 3.5, 24);
|
|
||||||
ctx.restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
// fields (recessed leather)
|
|
||||||
for (const fx of [leftX, rightX]) {
|
|
||||||
dropShadow(ctx, () => { ctx.fillStyle = '#123'; ctx.fillRect(X(fx), Y(FY), HALF_W, FH); }, { blur: 10, dx: 0, dy: 3, alpha: 0.7 });
|
|
||||||
leather(ctx, X(fx), Y(FY), HALF_W, FH);
|
|
||||||
}
|
|
||||||
// points
|
|
||||||
for (let half = 0; half < 2; half++) {
|
|
||||||
const fx = half === 0 ? leftX : rightX;
|
|
||||||
for (let col = 0; col < 6; col++) {
|
|
||||||
const ax = X(fx + col * PW), bx = ax + PW;
|
|
||||||
// top row starts light at the left of each half, bottom row starts dark
|
|
||||||
point(ctx, ax, bx, Y(FY), Y(FY + PH), col % 2 === 0);
|
|
||||||
point(ctx, ax, bx, Y(FY + FH), Y(FY + FH - PH), col % 2 === 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// the hinge / bar: olive wood with a centre seam and brass knuckles
|
|
||||||
ctx.save(); ctx.beginPath(); ctx.rect(X(barX), Y(FY), BAR_W, FH); ctx.clip();
|
|
||||||
oliveWood(ctx, rnd, X(barX), Y(FY), BAR_W, FH, true);
|
|
||||||
ctx.restore();
|
|
||||||
ctx.fillStyle = 'rgba(30,15,5,0.65)'; ctx.fillRect(X(barX + BAR_W / 2) - 1.5, Y(FY), 3, FH);
|
|
||||||
ctx.fillStyle = 'rgba(255,235,190,0.25)'; ctx.fillRect(X(barX + BAR_W / 2) + 1.5, Y(FY), 1, FH);
|
|
||||||
for (const yy of [FY + FH * 0.33, FY + FH * 0.67]) {
|
|
||||||
brassPlate(ctx, X(barX + BAR_W / 2) - 9, Y(yy) - 34, 18, 68);
|
|
||||||
for (let k = -2; k <= 2; k++) { ctx.fillStyle = 'rgba(80,55,15,0.6)'; ctx.fillRect(X(barX + BAR_W / 2) - 9, Y(yy) + k * 13, 18, 1.2); }
|
|
||||||
}
|
|
||||||
ctx.strokeStyle = 'rgba(30,15,5,0.55)'; ctx.lineWidth = 2;
|
|
||||||
ctx.strokeRect(X(barX), Y(FY), BAR_W, FH);
|
|
||||||
|
|
||||||
// bear-off tray: a grooved well with a divider
|
|
||||||
const tx = X(trayX), tw = TRAY_W;
|
|
||||||
dropShadow(ctx, () => { ctx.fillStyle = '#221'; ctx.fillRect(tx, Y(FY), tw, FH); }, { blur: 10, dx: 0, dy: 3, alpha: 0.7 });
|
|
||||||
const tg = ctx.createLinearGradient(tx, 0, tx + tw, 0);
|
|
||||||
tg.addColorStop(0, '#5a3a1c'); tg.addColorStop(0.5, '#6e4824'); tg.addColorStop(1, '#4e3218');
|
|
||||||
ctx.fillStyle = tg; ctx.fillRect(tx, Y(FY), tw, FH);
|
|
||||||
grain(ctx, rnd, tx, Y(FY), tw, FH, { vertical: true, lines: 14, tone: 'rgba(20,10,2,0.35)', wave: 4 });
|
|
||||||
for (let yy = FY + 6; yy < FY + FH; yy += 14) {
|
|
||||||
ctx.fillStyle = 'rgba(0,0,0,0.25)'; ctx.fillRect(tx + 8, Y(yy), tw - 16, 1.5);
|
|
||||||
ctx.fillStyle = 'rgba(255,220,170,0.08)'; ctx.fillRect(tx + 8, Y(yy) + 1.5, tw - 16, 1);
|
|
||||||
}
|
|
||||||
ctx.save(); ctx.beginPath(); ctx.rect(tx - 2, Y(MID_Y) - 15, tw + 4, 30); ctx.clip();
|
|
||||||
oliveWood(ctx, rnd, tx - 2, Y(MID_Y) - 15, tw + 4, 30);
|
|
||||||
ctx.restore();
|
|
||||||
rosette(ctx, tx + tw / 2, Y(MID_Y), 10);
|
|
||||||
ctx.strokeStyle = 'rgba(0,0,0,0.5)'; ctx.lineWidth = 3; ctx.strokeRect(tx + 1, Y(FY) + 1, tw - 2, FH - 2);
|
|
||||||
// the small rail between the field and the tray
|
|
||||||
ctx.fillStyle = 'rgba(40,20,5,0.35)'; ctx.fillRect(X(rightX + HALF_W), Y(FY), 2, FH);
|
|
||||||
|
|
||||||
addCanvas(scene, 'bg-case', c);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── checkers ─────────────────────────────────────────────────────────────────
|
|
||||||
function bakeCheckers(scene) {
|
|
||||||
const S = CHK.size, cx = S / 2, cy = S / 2 - 2, R = CR;
|
|
||||||
for (const color of ['white', 'black']) {
|
|
||||||
const c = canvas(S, S + 6), ctx = c.getContext('2d');
|
|
||||||
const face = color === 'white'
|
|
||||||
? ['#fbf3df', '#eadbb7', '#cdb88b']
|
|
||||||
: ['#6b4630', '#3e2618', '#22140b'];
|
|
||||||
// edge band (thickness, seen just below the face)
|
|
||||||
ctx.fillStyle = color === 'white' ? '#b49f72' : '#150b05';
|
|
||||||
ctx.beginPath(); ctx.arc(cx, cy + 5, R, 0, Math.PI * 2); ctx.fill();
|
|
||||||
ctx.fillStyle = color === 'white' ? 'rgba(255,255,255,0.25)' : 'rgba(255,200,150,0.12)';
|
|
||||||
ctx.fillRect(cx - R, cy + 2, R * 2, 1);
|
|
||||||
// face
|
|
||||||
const g = ctx.createRadialGradient(cx - R * 0.35, cy - R * 0.4, R * 0.1, cx, cy, R);
|
|
||||||
g.addColorStop(0, face[0]); g.addColorStop(0.6, face[1]); g.addColorStop(1, face[2]);
|
|
||||||
ctx.fillStyle = g;
|
|
||||||
ctx.beginPath(); ctx.arc(cx, cy, R, 0, Math.PI * 2); ctx.fill();
|
|
||||||
// turned lathe rings
|
|
||||||
for (const [k, a] of [[0.86, 0.35], [0.62, 0.3], [0.34, 0.25]]) {
|
|
||||||
ctx.strokeStyle = color === 'white' ? `rgba(120,95,50,${a})` : `rgba(0,0,0,${a + 0.15})`;
|
|
||||||
ctx.lineWidth = 1.6;
|
|
||||||
ctx.beginPath(); ctx.arc(cx, cy, R * k, 0, Math.PI * 2); ctx.stroke();
|
|
||||||
ctx.strokeStyle = color === 'white' ? 'rgba(255,255,255,0.55)' : 'rgba(255,210,170,0.16)';
|
|
||||||
ctx.lineWidth = 1;
|
|
||||||
ctx.beginPath(); ctx.arc(cx, cy + 1.2, R * k, Math.PI * 0.15, Math.PI * 0.85); ctx.stroke();
|
|
||||||
}
|
|
||||||
// centre inlay
|
|
||||||
const ig = ctx.createRadialGradient(cx - 2, cy - 2, 0.5, cx, cy, 7);
|
|
||||||
if (color === 'white') { ig.addColorStop(0, '#ffffff'); ig.addColorStop(0.5, '#d9e6ef'); ig.addColorStop(1, '#a9b8c4'); }
|
|
||||||
else { ig.addColorStop(0, '#fbe6a8'); ig.addColorStop(0.6, '#c99a3a'); ig.addColorStop(1, '#7a5a1c'); }
|
|
||||||
ctx.fillStyle = ig;
|
|
||||||
ctx.beginPath(); ctx.arc(cx, cy, 6.5, 0, Math.PI * 2); ctx.fill();
|
|
||||||
// gloss
|
|
||||||
const gl = ctx.createLinearGradient(cx - R, cy - R, cx, cy);
|
|
||||||
gl.addColorStop(0, color === 'white' ? 'rgba(255,255,255,0.55)' : 'rgba(255,220,190,0.28)');
|
|
||||||
gl.addColorStop(1, 'rgba(255,255,255,0)');
|
|
||||||
ctx.fillStyle = gl;
|
|
||||||
ctx.beginPath(); ctx.ellipse(cx - R * 0.32, cy - R * 0.38, R * 0.55, R * 0.3, -0.6, 0, Math.PI * 2); ctx.fill();
|
|
||||||
ctx.strokeStyle = color === 'white' ? 'rgba(90,70,30,0.55)' : 'rgba(0,0,0,0.75)';
|
|
||||||
ctx.lineWidth = 1.2;
|
|
||||||
ctx.beginPath(); ctx.arc(cx, cy, R - 0.5, 0, Math.PI * 2); ctx.stroke();
|
|
||||||
addCanvas(scene, `bg-chk-${color}`, c);
|
|
||||||
|
|
||||||
// standing on edge in the tray
|
|
||||||
const e = canvas(CHK.edgeW + 6, CHK.edgeH + 6), ex = e.getContext('2d');
|
|
||||||
ex.fillStyle = 'rgba(0,0,0,0.4)'; rr(ex, 4, 5, CHK.edgeW, CHK.edgeH, 5); ex.fill();
|
|
||||||
const eg = ex.createLinearGradient(0, 2, 0, 2 + CHK.edgeH);
|
|
||||||
eg.addColorStop(0, face[0]); eg.addColorStop(0.5, face[1]); eg.addColorStop(1, face[2]);
|
|
||||||
ex.fillStyle = eg; rr(ex, 2, 2, CHK.edgeW, CHK.edgeH, 5); ex.fill();
|
|
||||||
ex.strokeStyle = color === 'white' ? 'rgba(110,85,40,0.45)' : 'rgba(0,0,0,0.6)'; ex.lineWidth = 1;
|
|
||||||
for (const yy of [5, 2 + CHK.edgeH - 3]) { ex.beginPath(); ex.moveTo(6, yy); ex.lineTo(CHK.edgeW - 2, yy); ex.stroke(); }
|
|
||||||
rr(ex, 2, 2, CHK.edgeW, CHK.edgeH, 5); ex.stroke();
|
|
||||||
addCanvas(scene, `bg-edge-${color}`, e);
|
|
||||||
}
|
|
||||||
// contact shadow
|
|
||||||
const s = canvas(S + 20, S + 20), sx = s.getContext('2d');
|
|
||||||
const sg = sx.createRadialGradient((S + 20) / 2, (S + 20) / 2, R * 0.6, (S + 20) / 2, (S + 20) / 2, R + 10);
|
|
||||||
sg.addColorStop(0, 'rgba(0,0,0,0.55)'); sg.addColorStop(1, 'rgba(0,0,0,0)');
|
|
||||||
sx.fillStyle = sg; sx.fillRect(0, 0, S + 20, S + 20);
|
|
||||||
addCanvas(scene, 'bg-chk-shadow', s);
|
|
||||||
// selection glow ring
|
|
||||||
const gS = S + 30, gc = canvas(gS, gS), gx = gc.getContext('2d');
|
|
||||||
const gg = gx.createRadialGradient(gS / 2, gS / 2, R - 2, gS / 2, gS / 2, R + 14);
|
|
||||||
gg.addColorStop(0, 'rgba(255,214,90,0)'); gg.addColorStop(0.3, 'rgba(255,214,90,0.95)'); gg.addColorStop(1, 'rgba(255,214,90,0)');
|
|
||||||
gx.fillStyle = gg; gx.fillRect(0, 0, gS, gS);
|
|
||||||
addCanvas(scene, 'bg-glow', gc);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── cups ─────────────────────────────────────────────────────────────────────
|
|
||||||
function bakeCup(scene, key, tones) {
|
|
||||||
const P = 14;
|
|
||||||
const cw = AI_CUP.w, ch = AI_CUP.h;
|
|
||||||
const c = canvas(cw + P * 2, ch + P * 2), ctx = c.getContext('2d');
|
|
||||||
const top = P + 16, bot = P + ch - 10;
|
|
||||||
const lt = P + 6, rt = P + cw - 6, lb = P + 18, rb = P + cw - 18;
|
|
||||||
ctx.fillStyle = 'rgba(0,0,0,0.45)';
|
|
||||||
ctx.beginPath(); ctx.ellipse(P + cw / 2 + 8, bot + 2, cw * 0.42, 12, 0, 0, Math.PI * 2); ctx.fill();
|
|
||||||
ctx.save();
|
|
||||||
ctx.beginPath();
|
|
||||||
ctx.moveTo(lt, top); ctx.lineTo(rt, top); ctx.lineTo(rb, bot);
|
|
||||||
ctx.ellipse(P + cw / 2, bot, (rb - lb) / 2, 10, 0, 0, Math.PI, false);
|
|
||||||
ctx.lineTo(lt, top); ctx.closePath();
|
|
||||||
const g = ctx.createLinearGradient(lt, 0, rt, 0);
|
|
||||||
g.addColorStop(0, tones[0]); g.addColorStop(0.3, tones[1]); g.addColorStop(0.55, tones[2]); g.addColorStop(1, tones[3]);
|
|
||||||
ctx.fillStyle = g; ctx.fill();
|
|
||||||
ctx.clip();
|
|
||||||
ctx.fillStyle = noisePattern(ctx, 64, 50); ctx.fillRect(0, 0, c.width, c.height);
|
|
||||||
const cxm = P + cw / 2;
|
|
||||||
for (const yy of [top + 24, bot - 22]) {
|
|
||||||
const f = (yy - top) / (bot - top);
|
|
||||||
const hw = ((rt - lt) / 2) * (1 - f) + ((rb - lb) / 2) * f + 2, ry = 16 * (1 - f) + 10 * f;
|
|
||||||
ctx.fillStyle = 'rgba(0,0,0,0.25)';
|
|
||||||
ctx.beginPath(); ctx.ellipse(cxm, yy, hw, ry + 8, 0, 0, Math.PI); ctx.ellipse(cxm, yy - 14, hw, ry, 0, Math.PI, 0, true); ctx.fill();
|
|
||||||
const N = 22;
|
|
||||||
for (let k = 0; k < N; k++) {
|
|
||||||
const a0 = Math.PI * (k + 0.2) / N, a1 = Math.PI * (k + 0.75) / N;
|
|
||||||
const face = Math.sin((a0 + a1) / 2);
|
|
||||||
ctx.strokeStyle = `rgba(240,214,160,${0.3 + 0.6 * face})`;
|
|
||||||
ctx.lineWidth = 1 + 1.2 * face;
|
|
||||||
ctx.beginPath();
|
|
||||||
ctx.moveTo(cxm + hw * Math.cos(a0), yy - 4 + ry * Math.sin(a0));
|
|
||||||
ctx.lineTo(cxm + hw * Math.cos(a1), yy - 4 + ry * Math.sin(a1));
|
|
||||||
ctx.stroke();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// embossed meander square
|
|
||||||
ctx.strokeStyle = 'rgba(255,220,160,0.35)'; ctx.lineWidth = 2;
|
|
||||||
rr(ctx, cxm - 18, (top + bot) / 2 - 16, 36, 36, 6); ctx.stroke();
|
|
||||||
ctx.beginPath(); ctx.moveTo(cxm - 10, (top + bot) / 2 + 12); ctx.lineTo(cxm - 10, (top + bot) / 2 - 8); ctx.lineTo(cxm + 10, (top + bot) / 2 - 8); ctx.lineTo(cxm + 10, (top + bot) / 2 + 4); ctx.lineTo(cxm - 2, (top + bot) / 2 + 4); ctx.stroke();
|
|
||||||
ctx.restore();
|
|
||||||
// mouth
|
|
||||||
ctx.fillStyle = '#1a0b04';
|
|
||||||
ctx.beginPath(); ctx.ellipse(cxm, top, (rt - lt) / 2, 16, 0, 0, Math.PI * 2); ctx.fill();
|
|
||||||
ctx.strokeStyle = tones[1]; ctx.lineWidth = 5;
|
|
||||||
ctx.beginPath(); ctx.ellipse(cxm, top, (rt - lt) / 2 - 2, 14, 0, 0, Math.PI * 2); ctx.stroke();
|
|
||||||
ctx.strokeStyle = 'rgba(255,230,190,0.35)'; ctx.lineWidth = 1.5;
|
|
||||||
ctx.beginPath(); ctx.ellipse(cxm, top - 1, (rt - lt) / 2 - 2, 14, 0, Math.PI * 1.05, Math.PI * 1.95); ctx.stroke();
|
|
||||||
addCanvas(scene, key, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── doubling cube ────────────────────────────────────────────────────────────
|
|
||||||
function bakeCube(scene) {
|
|
||||||
const S = 64;
|
|
||||||
for (const v of CUBE_VALUES) {
|
|
||||||
const c = canvas(S + 12, S + 18), ctx = c.getContext('2d');
|
|
||||||
ctx.fillStyle = 'rgba(0,0,0,0.4)'; rr(ctx, 8, 12, S, S, 10); ctx.fill();
|
|
||||||
ctx.fillStyle = '#a99a78'; rr(ctx, 4, 10, S, S, 10); ctx.fill(); // side
|
|
||||||
const g = ctx.createLinearGradient(4, 4, 4 + S, 4 + S);
|
|
||||||
g.addColorStop(0, '#fffaf0'); g.addColorStop(1, '#e2d6bb');
|
|
||||||
ctx.fillStyle = g; rr(ctx, 4, 4, S, S, 10); ctx.fill(); // top face
|
|
||||||
ctx.strokeStyle = 'rgba(90,70,30,0.5)'; ctx.lineWidth = 1.5; rr(ctx, 4, 4, S, S, 10); ctx.stroke();
|
|
||||||
ctx.strokeStyle = 'rgba(122,36,32,0.6)'; ctx.lineWidth = 1.2; rr(ctx, 10, 10, S - 12, S - 12, 6); ctx.stroke();
|
|
||||||
ctx.fillStyle = '#7a2420';
|
|
||||||
ctx.font = `bold ${v >= 10 ? 30 : 36}px Georgia, serif`;
|
|
||||||
ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
|
|
||||||
ctx.fillText(String(v), 4 + S / 2, 4 + S / 2 + 2);
|
|
||||||
addCanvas(scene, `bg-cube-${v}`, c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── HUD pieces ───────────────────────────────────────────────────────────────
|
|
||||||
function bakePlate(scene) {
|
|
||||||
const rnd = seeded(33);
|
|
||||||
const w = OPP_PLATE.w, h = OPP_PLATE.h, P = 16;
|
|
||||||
const c = canvas(w + P * 2, h + P * 2), ctx = c.getContext('2d');
|
|
||||||
dropShadow(ctx, () => { ctx.fillStyle = '#f2ede2'; rr(ctx, P, P, w, h, 14); ctx.fill(); }, { blur: 18, dx: 6, dy: 10, alpha: 0.5 });
|
|
||||||
ctx.save(); rr(ctx, P, P, w, h, 14); ctx.clip();
|
|
||||||
ctx.fillStyle = '#efe9dc'; ctx.fillRect(P, P, w, h);
|
|
||||||
grain(ctx, rnd, P, P, w, h, { tone: 'rgba(120,100,70,0.16)', lines: 30, wave: 3 });
|
|
||||||
ctx.fillStyle = noisePattern(ctx, 64, 18); ctx.fillRect(P, P, w, h);
|
|
||||||
ctx.restore();
|
|
||||||
ctx.strokeStyle = '#2f6ea6'; ctx.lineWidth = 7; rr(ctx, P + 6, P + 6, w - 12, h - 12, 10); ctx.stroke();
|
|
||||||
ctx.strokeStyle = 'rgba(255,255,255,0.6)'; ctx.lineWidth = 1; rr(ctx, P + 11, P + 11, w - 22, h - 22, 7); ctx.stroke();
|
|
||||||
for (const [x, y] of [[P + 18, P + 18], [P + w - 18, P + 18], [P + 18, P + h - 18], [P + w - 18, P + h - 18]]) {
|
|
||||||
ctx.fillStyle = '#b8902e'; ctx.beginPath(); ctx.arc(x, y, 4, 0, Math.PI * 2); ctx.fill();
|
|
||||||
ctx.fillStyle = 'rgba(255,240,190,0.8)'; ctx.beginPath(); ctx.arc(x - 1, y - 1, 1.5, 0, Math.PI * 2); ctx.fill();
|
|
||||||
}
|
|
||||||
addCanvas(scene, 'bg-plate', c);
|
|
||||||
}
|
|
||||||
|
|
||||||
function bakeSlate(scene) {
|
|
||||||
const rnd = seeded(5);
|
|
||||||
const w = SLATE.w, h = SLATE.h, P = 16;
|
|
||||||
const c = canvas(w + P * 2, h + P * 2), ctx = c.getContext('2d');
|
|
||||||
dropShadow(ctx, () => { ctx.fillStyle = '#6b4a22'; rr(ctx, P, P, w, h, 10); ctx.fill(); }, { blur: 18, dx: 6, dy: 10, alpha: 0.5 });
|
|
||||||
ctx.save(); rr(ctx, P, P, w, h, 10); ctx.clip();
|
|
||||||
oliveWood(ctx, rnd, P, P, w, h);
|
|
||||||
ctx.restore();
|
|
||||||
const ix = P + 14, iy = P + 14, iw = w - 28, ih = h - 28;
|
|
||||||
const g = ctx.createLinearGradient(ix, iy, ix + iw, iy + ih);
|
|
||||||
g.addColorStop(0, '#2c3433'); g.addColorStop(1, '#1f2625');
|
|
||||||
ctx.fillStyle = g; ctx.fillRect(ix, iy, iw, ih);
|
|
||||||
ctx.fillStyle = noisePattern(ctx, 64, 30); ctx.fillRect(ix, iy, iw, ih);
|
|
||||||
// old chalk smudges
|
|
||||||
for (let i = 0; i < 16; i++) {
|
|
||||||
ctx.fillStyle = `rgba(230,230,220,${0.02 + rnd() * 0.04})`;
|
|
||||||
ctx.beginPath(); ctx.ellipse(ix + rnd() * iw, iy + rnd() * ih, 20 + rnd() * 50, 6 + rnd() * 14, rnd() * 3, 0, Math.PI * 2); ctx.fill();
|
|
||||||
}
|
|
||||||
ctx.strokeStyle = 'rgba(0,0,0,0.55)'; ctx.lineWidth = 3; ctx.strokeRect(ix, iy, iw, ih);
|
|
||||||
addCanvas(scene, 'bg-slate', c);
|
|
||||||
}
|
|
||||||
|
|
||||||
function bakeLedger(scene) {
|
|
||||||
const w = LEDGER.w, h = LEDGER.h, P = 14;
|
|
||||||
const c = canvas(w + P * 2, h + P * 2), ctx = c.getContext('2d');
|
|
||||||
dropShadow(ctx, () => { ctx.fillStyle = '#fbf8ef'; ctx.fillRect(P, P, w, h); }, { blur: 16, dx: 6, dy: 9, alpha: 0.45 });
|
|
||||||
ctx.fillStyle = '#fbf8ef'; ctx.fillRect(P, P, w, h);
|
|
||||||
ctx.fillStyle = noisePattern(ctx, 64, 12); ctx.fillRect(P, P, w, h);
|
|
||||||
// blue binding band with a title
|
|
||||||
ctx.fillStyle = '#2f6ea6'; ctx.fillRect(P, P, w, 40);
|
|
||||||
ctx.fillStyle = 'rgba(255,255,255,0.15)'; ctx.fillRect(P, P + 36, w, 2);
|
|
||||||
ctx.fillStyle = '#f6f2e6'; ctx.font = 'bold 18px Georgia, serif'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
|
|
||||||
ctx.fillText('ΤΑΒΛΙ · moves', P + w / 2, P + 20);
|
|
||||||
for (let y = P + 64; y < P + h - 6; y += 26) {
|
|
||||||
ctx.strokeStyle = 'rgba(47,110,166,0.28)'; ctx.lineWidth = 1;
|
|
||||||
ctx.beginPath(); ctx.moveTo(P + 8, y); ctx.lineTo(P + w - 8, y); ctx.stroke();
|
|
||||||
}
|
|
||||||
ctx.strokeStyle = 'rgba(190,60,60,0.35)';
|
|
||||||
ctx.beginPath(); ctx.moveTo(P + 44, P + 42); ctx.lineTo(P + 44, P + h); ctx.stroke();
|
|
||||||
// torn top edge
|
|
||||||
ctx.fillStyle = 'rgba(0,0,0,0.12)';
|
|
||||||
for (let x = P; x < P + w; x += 8) ctx.fillRect(x, P + 40, 4, 2);
|
|
||||||
addCanvas(scene, 'bg-ledger', c);
|
|
||||||
}
|
|
||||||
|
|
||||||
function bakeSlip(scene) {
|
|
||||||
const rnd = seeded(11);
|
|
||||||
const w = 520, h = 300, P = 18;
|
|
||||||
const c = canvas(w + P * 2, h + P * 2), ctx = c.getContext('2d');
|
|
||||||
const pts = [];
|
|
||||||
for (let x = 0; x <= w; x += 10) pts.push([P + x, P + (rnd() - 0.5) * 5]);
|
|
||||||
for (let y = 0; y <= h; y += 10) pts.push([P + w + (rnd() - 0.5) * 5, P + y]);
|
|
||||||
for (let x = w; x >= 0; x -= 10) pts.push([P + x, P + h + (rnd() - 0.5) * 6]);
|
|
||||||
for (let y = h; y >= 0; y -= 10) pts.push([P + (rnd() - 0.5) * 5, P + y]);
|
|
||||||
const path = () => { ctx.beginPath(); pts.forEach(([x, y], i) => (i ? ctx.lineTo(x, y) : ctx.moveTo(x, y))); ctx.closePath(); };
|
|
||||||
dropShadow(ctx, () => { ctx.fillStyle = '#fbf6e8'; path(); ctx.fill(); }, { blur: 20, dx: 8, dy: 12, alpha: 0.55 });
|
|
||||||
ctx.save(); path(); ctx.clip();
|
|
||||||
const g = ctx.createLinearGradient(0, P, 0, P + h);
|
|
||||||
g.addColorStop(0, '#fdf9ee'); g.addColorStop(1, '#efe6cf');
|
|
||||||
ctx.fillStyle = g; ctx.fillRect(0, 0, c.width, c.height);
|
|
||||||
ctx.fillStyle = noisePattern(ctx, 64, 14); ctx.fillRect(0, 0, c.width, c.height);
|
|
||||||
ctx.restore();
|
|
||||||
ctx.strokeStyle = 'rgba(47,110,166,0.5)'; ctx.lineWidth = 2;
|
|
||||||
ctx.strokeRect(P + 14, P + 14, w - 28, h - 28);
|
|
||||||
addCanvas(scene, 'bg-slip', c);
|
|
||||||
}
|
|
||||||
|
|
||||||
function bakeDapple(scene) {
|
|
||||||
const rnd = seeded(2024);
|
|
||||||
// painted at half resolution (it is blurred anyway) and shown at 2×
|
|
||||||
const w = 2400, h = 1500;
|
|
||||||
const c = canvas(w / 2, h / 2), ctx = c.getContext('2d');
|
|
||||||
ctx.scale(0.5, 0.5);
|
|
||||||
try { ctx.filter = 'blur(7px)'; } catch (_) { /* older canvas */ }
|
|
||||||
// clusters of vine leaves (dark) with sunny gaps
|
|
||||||
for (let k = 0; k < 46; k++) {
|
|
||||||
const cx = rnd() * w, cy = rnd() * h;
|
|
||||||
const n = 6 + Math.floor(rnd() * 10);
|
|
||||||
for (let i = 0; i < n; i++) {
|
|
||||||
const x = cx + (rnd() - 0.5) * 260, y = cy + (rnd() - 0.5) * 200;
|
|
||||||
const r = 26 + rnd() * 46;
|
|
||||||
ctx.fillStyle = `rgba(8,26,20,${0.35 + rnd() * 0.35})`;
|
|
||||||
ctx.save(); ctx.translate(x, y); ctx.rotate(rnd() * Math.PI);
|
|
||||||
// a five-lobed vine leaf
|
|
||||||
ctx.beginPath();
|
|
||||||
for (let a = 0; a <= 40; a++) {
|
|
||||||
const t = (a / 40) * Math.PI * 2;
|
|
||||||
const lobe = 0.72 + 0.28 * Math.abs(Math.cos(t * 2.5));
|
|
||||||
const px = Math.cos(t) * r * lobe, py = Math.sin(t) * r * lobe * 0.9;
|
|
||||||
if (a) ctx.lineTo(px, py); else ctx.moveTo(px, py);
|
|
||||||
}
|
|
||||||
ctx.closePath(); ctx.fill();
|
|
||||||
ctx.restore();
|
|
||||||
}
|
|
||||||
// a tendril
|
|
||||||
ctx.strokeStyle = 'rgba(8,26,20,0.4)'; ctx.lineWidth = 5;
|
|
||||||
ctx.beginPath(); ctx.moveTo(cx, cy);
|
|
||||||
ctx.bezierCurveTo(cx + 60, cy - 90, cx + 160, cy + 40, cx + 230, cy - 40);
|
|
||||||
ctx.stroke();
|
|
||||||
}
|
|
||||||
try { ctx.filter = 'none'; } catch (_) { /* older canvas */ }
|
|
||||||
addCanvas(scene, 'bg-dapple', c);
|
|
||||||
}
|
|
||||||
|
|
||||||
function bakeBits(scene) {
|
|
||||||
const s = canvas(32, 32), sx = s.getContext('2d');
|
|
||||||
const g = sx.createRadialGradient(16, 16, 0, 16, 16, 16);
|
|
||||||
g.addColorStop(0, 'rgba(255,255,255,1)'); g.addColorStop(0.4, 'rgba(255,240,200,0.7)'); g.addColorStop(1, 'rgba(255,240,200,0)');
|
|
||||||
sx.fillStyle = g; sx.fillRect(0, 0, 32, 32);
|
|
||||||
addCanvas(scene, 'bg-spark', s);
|
|
||||||
const st = canvas(64, 64), tx = st.getContext('2d');
|
|
||||||
const g2 = tx.createRadialGradient(32, 32, 0, 32, 32, 32);
|
|
||||||
g2.addColorStop(0, 'rgba(255,255,255,0.55)'); g2.addColorStop(1, 'rgba(255,255,255,0)');
|
|
||||||
tx.fillStyle = g2; tx.fillRect(0, 0, 64, 64);
|
|
||||||
addCanvas(scene, 'bg-steam', st);
|
|
||||||
}
|
|
||||||
|
|
||||||
let baked = false;
|
|
||||||
export async function prepareBackgammonArt(scene) {
|
|
||||||
try {
|
|
||||||
if (document.fonts?.load) {
|
|
||||||
await Promise.race([
|
|
||||||
Promise.all([
|
|
||||||
document.fonts.load('20px Righteous'), document.fonts.load('14px "Julius Sans One"'),
|
|
||||||
document.fonts.load('30px YummyCupcakes'),
|
|
||||||
]),
|
|
||||||
new Promise((res) => setTimeout(res, 1200)),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
} catch (_) { /* fall back to Georgia */ }
|
|
||||||
if (!baked || !scene.textures.exists('bg-room')) {
|
|
||||||
bakeRoom(scene); bakeCase(scene); bakeCheckers(scene);
|
|
||||||
bakeCup(scene, 'bg-cup-white', ['#5a3412', '#b07a3a', '#8e5c26', '#4a2a0e']);
|
|
||||||
bakeCup(scene, 'bg-cup-black', ['#3a0e0c', '#8a2a24', '#6a1c18', '#2a0806']);
|
|
||||||
bakeCube(scene); bakePlate(scene); bakeSlate(scene); bakeLedger(scene); bakeSlip(scene);
|
|
||||||
bakeDapple(scene); bakeBits(scene);
|
|
||||||
baked = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export { shade };
|
|
||||||
|
|
@ -1,177 +0,0 @@
|
||||||
// BackgammonBearoff.js — exact one-sided bear-off table. Phaser-free.
|
|
||||||
//
|
|
||||||
// For every arrangement of ≤ 15 checkers on the six home points (C(21,6) =
|
|
||||||
// 54,264 positions) it stores the expected number of rolls to bear everything
|
|
||||||
// off under rolls-minimising play, and the second moment, so a two-sided race
|
|
||||||
// can be turned into a win probability.
|
|
||||||
//
|
|
||||||
// Built by DP in pip order (children always have fewer pips). Every
|
|
||||||
// (position, die) single-step child list is precomputed into flat Int32Arrays,
|
|
||||||
// then h_k(pos, d) = best E after k more moves of die d drives non-doubles
|
|
||||||
// (two orders) and doubles (four moves). The build can run in slices
|
|
||||||
// (buildStep) so the scene never stalls; ready() says when it's done.
|
|
||||||
//
|
|
||||||
// expectedRolls(counts[6]) → { e, m2 } | null (null until built)
|
|
||||||
// raceWinProb(meHome, opHome) → P(me wins) with op ON ROLL
|
|
||||||
|
|
||||||
const N_POINTS = 6;
|
|
||||||
const MAXC = 15;
|
|
||||||
|
|
||||||
let positions = null; // Int32Array of packed keys, in pip order
|
|
||||||
let indexOf = null; // Map packed → index
|
|
||||||
let E = null, M2 = null;
|
|
||||||
let H = null, HM = null; // h_k tables: [(pos*6 + d-1)*3 + (k-1)]
|
|
||||||
let cursor = 0;
|
|
||||||
let total = 0;
|
|
||||||
|
|
||||||
const pack = (c) => c[0] | (c[1] << 4) | (c[2] << 8) | (c[3] << 12) | (c[4] << 16) | (c[5] << 20);
|
|
||||||
const unpack = (k, out) => { for (let i = 0; i < 6; i++) out[i] = (k >> (i * 4)) & 15; return out; };
|
|
||||||
|
|
||||||
function enumeratePositions() {
|
|
||||||
const list = [];
|
|
||||||
const c = [0, 0, 0, 0, 0, 0];
|
|
||||||
const rec = (i, left) => {
|
|
||||||
if (i === N_POINTS) { list.push({ key: pack(c), pips: c.reduce((a, n, j) => a + n * (j + 1), 0) }); return; }
|
|
||||||
for (let n = 0; n <= left; n++) { c[i] = n; rec(i + 1, left - n); }
|
|
||||||
c[i] = 0;
|
|
||||||
};
|
|
||||||
rec(0, MAXC);
|
|
||||||
list.sort((a, b) => a.pips - b.pips);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
function init() {
|
|
||||||
const list = enumeratePositions();
|
|
||||||
total = list.length;
|
|
||||||
positions = new Int32Array(total);
|
|
||||||
indexOf = new Map();
|
|
||||||
list.forEach((p, i) => { positions[i] = p.key; indexOf.set(p.key, i); });
|
|
||||||
E = new Float32Array(total);
|
|
||||||
M2 = new Float32Array(total);
|
|
||||||
H = new Float32Array(total * 18);
|
|
||||||
HM = new Float32Array(total * 18);
|
|
||||||
cursor = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const tmp = [0, 0, 0, 0, 0, 0];
|
|
||||||
const tmp2 = [0, 0, 0, 0, 0, 0];
|
|
||||||
|
|
||||||
// Children of position c for one die: indices.
|
|
||||||
function childrenOf(c, die, out) {
|
|
||||||
out.length = 0;
|
|
||||||
let hi = -1;
|
|
||||||
for (let i = 5; i >= 0; i--) if (c[i]) { hi = i; break; }
|
|
||||||
if (hi < 0) return out;
|
|
||||||
for (let i = 0; i < 6; i++) {
|
|
||||||
if (!c[i]) continue;
|
|
||||||
const to = i - die;
|
|
||||||
if (to < -1 && i !== hi) continue;
|
|
||||||
for (let j = 0; j < 6; j++) tmp2[j] = c[j];
|
|
||||||
tmp2[i]--;
|
|
||||||
if (to >= 0) tmp2[to]++;
|
|
||||||
out.push(indexOf.get(pack(tmp2)));
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
const kids = [];
|
|
||||||
|
|
||||||
function processOne(idx) {
|
|
||||||
const c = unpack(positions[idx], tmp);
|
|
||||||
let empty = true;
|
|
||||||
for (let i = 0; i < 6; i++) if (c[i]) { empty = false; break; }
|
|
||||||
if (empty) {
|
|
||||||
E[idx] = 0; M2[idx] = 0;
|
|
||||||
for (let q = 0; q < 18; q++) { H[idx * 18 + q] = 0; HM[idx * 18 + q] = 0; }
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// per-die child lists (reused below)
|
|
||||||
const lists = [];
|
|
||||||
for (let d = 1; d <= 6; d++) lists.push(childrenOf(c, d, []).slice());
|
|
||||||
|
|
||||||
// expected rolls for this position: average over 36 rolls of best play
|
|
||||||
let e = 0, m2 = 0;
|
|
||||||
for (let a = 1; a <= 6; a++) {
|
|
||||||
for (let b = a; b <= 6; b++) {
|
|
||||||
let best = Infinity, bestM = 0;
|
|
||||||
if (a === b) {
|
|
||||||
// four moves: first step here, then h_3 on the child
|
|
||||||
for (const ch of lists[a - 1]) {
|
|
||||||
const v = H[(ch * 6 + a - 1) * 3 + 2], vm = HM[(ch * 6 + a - 1) * 3 + 2];
|
|
||||||
if (v < best) { best = v; bestM = vm; }
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (const ch of lists[a - 1]) {
|
|
||||||
const v = H[(ch * 6 + b - 1) * 3], vm = HM[(ch * 6 + b - 1) * 3];
|
|
||||||
if (v < best) { best = v; bestM = vm; }
|
|
||||||
}
|
|
||||||
for (const ch of lists[b - 1]) {
|
|
||||||
const v = H[(ch * 6 + a - 1) * 3], vm = HM[(ch * 6 + a - 1) * 3];
|
|
||||||
if (v < best) { best = v; bestM = vm; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const w = a === b ? 1 : 2;
|
|
||||||
e += w * (1 + best);
|
|
||||||
m2 += w * (1 + 2 * best + bestM);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
E[idx] = e / 36;
|
|
||||||
M2[idx] = m2 / 36;
|
|
||||||
|
|
||||||
// h_k(this, d): best (E, M2) after k more single moves of die d from here.
|
|
||||||
for (let d = 1; d <= 6; d++) {
|
|
||||||
const base = (idx * 6 + d - 1) * 3;
|
|
||||||
let b1 = Infinity, m1 = 0;
|
|
||||||
for (const ch of lists[d - 1]) if (E[ch] < b1) { b1 = E[ch]; m1 = M2[ch]; }
|
|
||||||
H[base] = b1; HM[base] = m1;
|
|
||||||
for (let k = 2; k <= 3; k++) {
|
|
||||||
let bk = Infinity, mk = 0;
|
|
||||||
for (const ch of lists[d - 1]) {
|
|
||||||
const v = H[(ch * 6 + d - 1) * 3 + (k - 2)];
|
|
||||||
if (v < bk) { bk = v; mk = HM[(ch * 6 + d - 1) * 3 + (k - 2)]; }
|
|
||||||
}
|
|
||||||
H[base + k - 1] = bk; HM[base + k - 1] = mk;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Build up to `budget` positions; returns true when the table is complete. */
|
|
||||||
export function buildStep(budget = 4000) {
|
|
||||||
if (!positions) init();
|
|
||||||
const end = Math.min(total, cursor + budget);
|
|
||||||
for (; cursor < end; cursor++) processOne(cursor);
|
|
||||||
return cursor >= total;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function buildAll() { while (!buildStep(1e6)); }
|
|
||||||
export function ready() { return !!positions && cursor >= total; }
|
|
||||||
export function size() { return total || enumeratePositions().length; }
|
|
||||||
|
|
||||||
export function expectedRolls(counts) {
|
|
||||||
if (!ready()) return null;
|
|
||||||
for (let i = 0; i < 6; i++) if (counts[i] > MAXC) return null;
|
|
||||||
const idx = indexOf.get(pack(counts));
|
|
||||||
if (idx === undefined) return null;
|
|
||||||
return { e: E[idx], m2: M2[idx] };
|
|
||||||
}
|
|
||||||
|
|
||||||
// Standard normal CDF.
|
|
||||||
export function phi(x) {
|
|
||||||
const t = 1 / (1 + 0.2316419 * Math.abs(x));
|
|
||||||
const d = 0.3989423 * Math.exp(-x * x / 2);
|
|
||||||
const p = d * t * (0.3193815 + t * (-0.3565638 + t * (1.781478 + t * (-1.821256 + t * 1.330274))));
|
|
||||||
return x > 0 ? 1 - p : p;
|
|
||||||
}
|
|
||||||
|
|
||||||
// P(me wins) when both sides are bearing off and op is on roll. Uses the
|
|
||||||
// normal approximation to the difference of the two roll-count distributions.
|
|
||||||
export function raceWinProb(meHome, opHome) {
|
|
||||||
const a = expectedRolls(meHome), b = expectedRolls(opHome);
|
|
||||||
if (!a || !b) return null;
|
|
||||||
if (a.e === 0) return 1;
|
|
||||||
if (b.e === 0) return 0;
|
|
||||||
const va = Math.max(0, a.m2 - a.e * a.e), vb = Math.max(0, b.m2 - b.e * b.e);
|
|
||||||
const sd = Math.max(0.35, Math.sqrt(va + vb));
|
|
||||||
// op wins if N_op ≤ N_me (op rolls first): P(me) = P(N_me − N_op ≤ −1)
|
|
||||||
return phi((-0.5 - (a.e - b.e)) / sd);
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue