Implement playable Fuji scenario one with BGS engine and Svelte viewer
7
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
node_modules/
|
||||
dist/
|
||||
dist-test/
|
||||
*.tgz
|
||||
.env*
|
||||
!.env.example
|
||||
work/
|
||||
10
.oxfmtrc.json
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"printWidth": 120,
|
||||
"tabWidth": 2,
|
||||
"useTabs": true,
|
||||
"semi": true,
|
||||
"singleQuote": false,
|
||||
"trailingComma": "es5",
|
||||
"svelte": true,
|
||||
"ignorePatterns": ["**/dist/**", "**/dist-test/**", "**/node_modules/**", "pnpm-lock.yaml"]
|
||||
}
|
||||
13
AGENTS.md
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# Fuji development
|
||||
|
||||
Use English for code, identifiers, documentation, tests and source UI strings.
|
||||
|
||||
- Node 24+, pnpm workspace, TypeScript strict, Svelte 5 runes.
|
||||
- Run `pnpm check` before commits; run simulation when changing state transitions.
|
||||
- Apply moves to a clone and validate before returning. Invalid actions must leave the input state and RNG counter unchanged.
|
||||
- All gameplay randomness uses the seed and counter in engine state. Never use `Math.random` in the engine.
|
||||
- Never expose seed, counter, deck order, private roll history or hidden dice through viewer state, logs or helpers. The local hot-seat harness is intentionally separate from the BGS bundle.
|
||||
- Rules data comes from the supplied production files. Record uncertain interpretations in `docs/rules-status.md`; do not silently invent rule data.
|
||||
- Keep source assets separate from the source-code license. Do not upload the original production PDFs to the repository.
|
||||
- Match BGS's emitter contract; do not implement a second postMessage bridge. Uplink payloads must be plain serializable values.
|
||||
- The beta is not ready for publication until the platform clock and cooperative result concerns in `docs/bgs-integration.md` are resolved or explicitly bounded for a private test.
|
||||
661
LICENSE
Normal file
|
|
@ -0,0 +1,661 @@
|
|||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
9
NOTICE.md
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# Notices
|
||||
|
||||
Source code is licensed under AGPL-3.0-only. The small emitter implementation follows the existing Boardgamers Outpost viewer (https://github.com/boardgamers/outpost), whose package declares AGPL-3.0.
|
||||
|
||||
Fuji game design: Wolfgang Warsch.
|
||||
Illustrations: Weberson Santiago.
|
||||
Publisher: Feuerland Spiele.
|
||||
|
||||
Artwork was supplied for this adaptation through the project owner. Artwork and other publisher material are not covered by the source-code license. The original production PDFs are kept outside the repository.
|
||||
49
README.md
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
# Fuji
|
||||
|
||||
A playable first implementation of Wolfgang Warsch’s cooperative game for Boardgamers, with artwork by Weberson Santiago supplied by Feuerland.
|
||||
|
||||
This is a **local alpha**, not a published or publisher-approved final adaptation. It implements scenario 1, two to four players (two-player variant A), all four difficulty levels, six skills and fifteen equipment effects. The visual direction uses the original illustrations as an interactive landscape, with private dice totals, route previews, revealed comparisons and state-driven lava.
|
||||
|
||||
## Run
|
||||
|
||||
Requires Node 24+ and pnpm 11.
|
||||
|
||||
```sh
|
||||
pnpm install
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
Open `http://127.0.0.1:5187`. The local harness keeps a playtest in browser storage. Click an adventurer to switch seats. **Play next teammate action** advances a simple, non-omniscient test player one action; it is a testing aid, not a strategic AI. **New game** replaces the local save.
|
||||
|
||||
```sh
|
||||
pnpm check
|
||||
pnpm simulate
|
||||
pnpm fmt
|
||||
```
|
||||
|
||||
The engine tests cover deterministic replay, invalid-move atomicity, private information, movement, lava, injury timing and equipment interactions. Simulation runs 150 complete expeditions across player counts and difficulty levels and verifies exact replays. Browser smoke testing covers setup, route selection, every round phase, game end, mobile overflow and the help dialog.
|
||||
|
||||
## Packages
|
||||
|
||||
- `packages/engine`: pure TypeScript rules, serializable state, seeded randomness, immutable move application and `dist/wrapper.js` for BGS.
|
||||
- `packages/viewer`: Svelte 5 viewer. Builds a self-contained `dist/fuji-viewer.iife.js` exposing `window.fuji.launch(selector)` and a stylesheet. The BGS host owns chat, clocks and the iframe message protocol.
|
||||
- `scripts/extract-assets.py`: reproducible extraction from the supplied production PDFs. Original archives are not included in this repository.
|
||||
- `docs/rules-status.md`: implementation scope, evidence and unresolved rule details.
|
||||
- `docs/bgs-integration.md`: packaging, protocol and remaining platform integration work.
|
||||
|
||||
## Artwork
|
||||
|
||||
The supplied artwork is embedded in optimized WebP assets. Its copyright remains with the respective rights holders; the source-code license does not license the illustrations. The PDFs contain illustrations separate from symbols, but do not supply editable scene layers. Further art direction and animation work can build on this first playable version.
|
||||
|
||||
Code, identifiers, documentation and current UI copy are in English.
|
||||
|
||||
## Browser checks
|
||||
|
||||
With `pnpm dev` already running and a current `pnpm build`:
|
||||
|
||||
```sh
|
||||
pnpm exec playwright install chromium
|
||||
pnpm test:browser
|
||||
```
|
||||
|
||||
If Chromium is already installed in a non-default location, set `FUJI_CHROMIUM_EXECUTABLE` to its executable path. Screenshots are written under the ignored `work/browser` directory. The second smoke test loads the actual production bundle with a minimal BGS emitter host, checks readiness and state refresh, verifies the move payload, and confirms that Wireless exposes the correct dice without loading the local harness.
|
||||
28
bgs-gameinfo.draft.json
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"label": "Fuji",
|
||||
"description": "Escape Mount Fuji together. Private alpha: scenario 1.",
|
||||
"players": [2, 3, 4],
|
||||
"credits": "Game design: Wolfgang Warsch. Illustrations: Weberson Santiago. Publisher: Feuerland Spiele.",
|
||||
"public": false,
|
||||
"engine": { "package": { "name": "fuji-engine", "version": "0.1.0" }, "entryPoint": "dist/wrapper.js" },
|
||||
"viewer": {
|
||||
"url": "",
|
||||
"topLevelVariable": "fuji",
|
||||
"replayable": false,
|
||||
"dependencies": { "scripts": [], "stylesheets": [] }
|
||||
},
|
||||
"options": [
|
||||
{
|
||||
"name": "difficulty",
|
||||
"label": "Difficulty",
|
||||
"type": "select",
|
||||
"default": "1",
|
||||
"items": [
|
||||
{ "name": "1", "label": "Level 1" },
|
||||
{ "name": "2", "label": "Level 2" },
|
||||
{ "name": "3", "label": "Level 3" },
|
||||
{ "name": "4", "label": "Level 4" }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
34
docs/bgs-integration.md
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# BGS integration
|
||||
|
||||
## Contract already implemented
|
||||
|
||||
Engine entry point: `dist/wrapper.js` from `fuji-engine`. The wrapper exports init, move, ended, scores, rankings, currentPlayer, dropPlayer, logLength, logSlice, stripSecret, round, replay and setPlayerMetaData. `hashSeed = true`; the seed never appears in a stripped view. No `moveAI` export is provided yet.
|
||||
|
||||
Viewer: self-contained IIFE, global `fuji`, function `launch(selector)` returning an emitter. The bridge consumes state/player events, requests fresh state on state updates and game logs, forwards moves without double wrapping, and announces readiness after rendering the initial state. The host continues to provide chat, clocks, identity and iframe messaging. Source assets are bundled as data URLs, so the initial viewer has no independent asset-hosting requirement.
|
||||
|
||||
```sh
|
||||
pnpm check
|
||||
cd packages/engine
|
||||
pnpm pack
|
||||
```
|
||||
|
||||
Upload the engine tarball and viewer JS/CSS together. The draft registration file intentionally contains empty URLs until real uploads exist. Do not run a publication operation without the user's supplied admin token. Keep `public: false` and `replayable: false` for the first private test.
|
||||
|
||||
## Platform work required before a normal timed beta
|
||||
|
||||
BGS credits the per-move clock increment for each persisted engine action. Fuji has public, revisable planning and multi-person equipment effects. Persisting those events is necessary so another player's response cannot overwrite or lose them, but an increment on every planning edit would allow time farming. `toSave: undefined` is not a safe substitute here: it would discard the shared intermediate state.
|
||||
|
||||
The platform needs a supported way for the engine to indicate which persisted actions earn a time increment, or a carefully designed equivalent. A private test with zero per-move increment avoids that particular issue, but this is not yet verified on a running BGS instance. Do not claim full timed integration from the standalone playtest alone.
|
||||
|
||||
During planning and equipment phases `currentPlayer` includes all players, including those marked ready, so the BGS turn gate permits revisions and reactions before the phase closes. This also means their clocks keep running until the phase changes; the UX and clock policy need explicit integration testing.
|
||||
|
||||
Fuji has a shared win/loss. The wrapper gives all players the same ranking and reports their individual contributions, but BGS's result display and Elo handling need to be checked for a cooperative title. A group loss must not appear as a competitive draw or grant inappropriate Elo.
|
||||
|
||||
## Validation still requiring a running BGS test
|
||||
|
||||
- Register a non-public version and grant access to test accounts.
|
||||
- Connect 2–4 separate sessions and a spectator; check private dice and public readiness.
|
||||
- Reload and reconnect during an equipment request, reroll and injury selection.
|
||||
- Check clock increments and ready-state behavior using the policy described above.
|
||||
- Verify team win/loss presentation, no competitive rating side effects, and player-drop behavior.
|
||||
- Check the actual iframe bundle and style uploads, not only the Vite dev harness.
|
||||
49
docs/rules-status.md
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
# Rules status
|
||||
|
||||
## Evidence
|
||||
|
||||
The publisher-supplied English production rulebook is `EN_Fuji_Regel_PRINT_3_130918.pdf` (13 September 2018). Terrain faces are transcribed from `fuji_land_front_Print3.pdf`; setup from scenario card 1; skills and equipment from the English fronts and rulebook appendix. The stamina track has exhaustion at step 25, with injury thresholds at steps 5, 10, 15 and 20.
|
||||
|
||||
The terrain names used in the UI are descriptive navigation labels, not printed card titles. Terrain IDs are the one-based production PDF page numbers.
|
||||
|
||||
Dice were inferred from 17 user-supplied groups (88 dice, 148 visible faces). Under the three-types/two-of-each model, exactly one value/color composition fits every observation:
|
||||
|
||||
| Value | A | B | C |
|
||||
| ----- | ------ | ------ | ------ |
|
||||
| 1 | Blue | Yellow | Pink |
|
||||
| 2 | Yellow | Pink | Blue |
|
||||
| 3 | Pink | Blue | Yellow |
|
||||
| 4 | Pink | Blue | Yellow |
|
||||
| 5 | Yellow | Pink | Blue |
|
||||
| 6 | Blue | Yellow | Pink |
|
||||
|
||||
Each full set contains two of each type. This remains observation-derived rather than publisher-certified. Faces 1 and 6 have different values but the same color in all three types, so Tape and Compass do not introduce a color change.
|
||||
|
||||
## Implemented first slice
|
||||
|
||||
- Scenario 1, including the additional village and split starting positions at four players.
|
||||
- All 24 landscape and 6 village card criteria, including AND/OR conditions and reroll symbols; scenario setup shuffles the appropriate decks.
|
||||
- Two-player variant A: six neutral dice, three visible during planning and three hidden until reveal. No neutral pawn.
|
||||
- Four difficulty levels; strict comparisons against seated neighbors; ties fail; stamina and immediate team defeat/victory.
|
||||
- Equipment preparation choices and one-die removal for five-die skills.
|
||||
- Six skills, fifteen equipment effects, donor consent for the lighter, per-player mandatory Carabiner rerolls, staged Water rerolls and Tinkerer reuse.
|
||||
- Set-aside dice visible to everyone and excluded from comparisons; temporary loans return after the round; leg-injury removal occurs after all comparisons.
|
||||
- Phase-five movement order is chosen by the players. Power bars are offered by their owner, rather than automatically spent by the recipient.
|
||||
- Additional eruptions are applied when traversing eruption markers; ordinary eruptions propagate one wave, never recursively through the entire map.
|
||||
- Win triggers as soon as everyone reaches the village, before further stamina deductions or eruptions.
|
||||
|
||||
## Deliberate alpha boundaries and interpretations
|
||||
|
||||
1. Only scenario 1 is enabled. Scenarios 2–7, the advanced two-player variant B and the extra-thrill double-eruption variant are not yet implemented.
|
||||
2. For a five-die skill, the player chooses which die to leave behind before any dice are rolled. The supplied material has not established the official selection procedure. This is an explicit provisional rule.
|
||||
3. The two-player simple variant splits one of each inferred type into the visible and hidden halves. The text specifies three visible and three hidden dice but does not mandate this split.
|
||||
4. A planned path is explicit. If an earlier extra eruption blocks that path, resolution treats it as a failed move unless an alternative legal path to the same locked destination is supplied. Check this interpretation against the publisher before beta release.
|
||||
5. Pocketknife follows the printed English equipment card: copy equipment belonging to another player. The appendix wording is broader; confirm whether copying one's own equipment should also be allowed.
|
||||
6. The local skill assignment is fixed for the first slice (Buddy, Gatherer, Equipment manager, then Survivalist); the engine accepts a `skills` array, but a complete pregame skill/character selection UI is still needed.
|
||||
7. Dropping a player ends the cooperative expedition. No replacement bot is enabled in the BGS wrapper.
|
||||
8. Live state and the journal work. Full server replay exists, but viewer replay controls are not implemented, so the BGS viewer must be registered with `replayable: false`.
|
||||
9. Original PDF art is usable and extracted, but the environment is still a first visual pass. It is not yet the final animation/presentation quality intended for Feuerland.
|
||||
|
||||
## Next acceptance checks
|
||||
|
||||
Play full expeditions with people familiar with the physical game. Verify the provisional interpretations, five-die selection and every equipment/skill combination against the physical reference. Extend scenario data from the already-supplied seven cards. Validate BGS multiplayer, clocks, reconnection and cooperative outcomes before publication.
|
||||
20
package.json
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"name": "fuji",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "pnpm --filter fuji-engine build && pnpm --filter fuji-viewer dev",
|
||||
"build": "pnpm --filter fuji-engine build && pnpm --filter fuji-viewer build",
|
||||
"test": "pnpm --filter fuji-engine test",
|
||||
"check": "pnpm fmt:check && pnpm build && pnpm --filter fuji-viewer check && pnpm test",
|
||||
"fmt": "oxfmt",
|
||||
"fmt:check": "oxfmt --check",
|
||||
"simulate": "pnpm --filter fuji-engine build && node scripts/simulate.mjs",
|
||||
"test:browser": "node tests/browser-smoke.mjs && node tests/bgs-bundle-smoke.mjs"
|
||||
},
|
||||
"devDependencies": {
|
||||
"oxfmt": "0.61.0",
|
||||
"playwright": "1.62.1"
|
||||
},
|
||||
"packageManager": "pnpm@11.18.0"
|
||||
}
|
||||
3
packages/engine/index.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
export * from "./src/data.js";
|
||||
export * from "./src/types.js";
|
||||
export * from "./src/game.js";
|
||||
29
packages/engine/package.json
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"name": "fuji-engine",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"license": "AGPL-3.0-only",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"exports": {
|
||||
".": "./dist/index.js",
|
||||
"./wrapper": "./dist/wrapper.js"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
|
||||
"test": "tsc --outDir dist-test && node --test dist-test/src/*.spec.js",
|
||||
"prepack": "pnpm build"
|
||||
},
|
||||
"dependencies": {
|
||||
"seedrandom": "3.0.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "24.10.1",
|
||||
"@types/seedrandom": "3.0.8",
|
||||
"typescript": "5.9.3"
|
||||
}
|
||||
}
|
||||
185
packages/engine/src/data.ts
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
export type Color = "blue" | "pink" | "yellow";
|
||||
export type Face = { value: number; color: Color };
|
||||
export const DICE: readonly (readonly Color[])[] = [
|
||||
["blue", "yellow", "pink", "pink", "yellow", "blue"],
|
||||
["yellow", "pink", "blue", "blue", "pink", "yellow"],
|
||||
["pink", "blue", "yellow", "yellow", "blue", "pink"],
|
||||
];
|
||||
export type Requirement = { colors?: Color[]; values?: number[]; parity?: "odd" | "even"; combine?: "or" };
|
||||
export type Terrain = {
|
||||
id: number;
|
||||
name: string;
|
||||
kind: "land" | "village" | "rubble" | "volcano";
|
||||
requirement: Requirement;
|
||||
reroll: boolean;
|
||||
};
|
||||
const t = (
|
||||
id: number,
|
||||
name: string,
|
||||
requirement: Requirement,
|
||||
reroll = false,
|
||||
kind: Terrain["kind"] = "land"
|
||||
): Terrain => ({ id, name, requirement, reroll, kind });
|
||||
export const TERRAINS: Terrain[] = [
|
||||
t(1, "Mount Fuji", {}, false, "volcano"),
|
||||
t(2, "Upper scree", {}, false, "rubble"),
|
||||
t(3, "Lower scree", {}, false, "rubble"),
|
||||
t(4, "Lake temple", { colors: ["yellow"], values: [6], combine: "or" }),
|
||||
t(5, "Sunlit shrine", { values: [1, 3] }, true),
|
||||
t(6, "Flooded forest", { values: [2, 4] }),
|
||||
t(7, "Forest cabin", { colors: ["pink"], parity: "odd" }),
|
||||
t(8, "Hilltop lookout", { parity: "even" }),
|
||||
t(9, "Red bridge", { colors: ["yellow"], parity: "even" }),
|
||||
t(10, "Hidden passage", { values: [1, 2] }, true),
|
||||
t(11, "Lakeside gate", { colors: ["yellow"], values: [4], combine: "or" }),
|
||||
t(12, "Leaning shelter", { colors: ["pink"], values: [5], combine: "or" }),
|
||||
t(13, "Bamboo grove", { colors: ["blue"], parity: "odd" }),
|
||||
t(14, "Shrine steps", { colors: ["pink", "blue"], parity: "odd" }),
|
||||
t(15, "Forest waterfall", { colors: ["blue"], values: [1, 2, 3] }, true),
|
||||
t(16, "Wooden crossing", { colors: ["pink", "blue", "yellow"] }),
|
||||
t(17, "Sunken trail", { values: [3, 6] }),
|
||||
t(18, "Riverside pavilion", { colors: ["yellow"], values: [1, 2, 3] }, true),
|
||||
t(19, "Mountain staircase", { parity: "odd" }),
|
||||
t(20, "Golden gate", { colors: ["yellow"], parity: "odd" }),
|
||||
t(21, "Bamboo path", { colors: ["pink", "blue"] }),
|
||||
t(22, "Lakeside shelter", { colors: ["blue"], values: [6], combine: "or" }),
|
||||
t(23, "Sunlit hillside", { colors: ["pink"], values: [1, 2, 3] }, true),
|
||||
t(24, "Forest sanctuary", { colors: ["pink", "blue"], parity: "even" }),
|
||||
t(25, "River bend", { colors: ["yellow", "blue"] }),
|
||||
t(26, "Riverside house", { colors: ["pink"], values: [4], combine: "or" }),
|
||||
t(27, "Stone path", { values: [3, 5] }),
|
||||
t(28, "Village pagoda", { colors: ["pink"], parity: "even" }, false, "village"),
|
||||
t(29, "Blossom square", { colors: ["blue"], values: [5], combine: "or" }, false, "village"),
|
||||
t(30, "Village gate", { colors: ["yellow", "pink"] }, false, "village"),
|
||||
t(31, "Village garden", { values: [1, 2, 3] }, true, "village"),
|
||||
t(32, "Village bridge", { colors: ["blue"], parity: "even" }, false, "village"),
|
||||
t(33, "Village street", { values: [4, 6] }, false, "village"),
|
||||
];
|
||||
export const terrain = (id: number): Terrain => {
|
||||
const out = TERRAINS.find((t) => t.id === id);
|
||||
if (!out) throw Error("Unknown terrain");
|
||||
return out;
|
||||
};
|
||||
export function matches(face: Face, r: Requirement): boolean {
|
||||
const c = !r.colors || r.colors.includes(face.color);
|
||||
const v = !r.values || r.values.includes(face.value);
|
||||
const p = !r.parity || face.value % 2 === (r.parity === "odd" ? 1 : 0);
|
||||
return face.value > 0 && (r.combine === "or" ? c || v : c && v && p);
|
||||
}
|
||||
export function requirementLabel(r: Requirement): string {
|
||||
const colors = r.colors?.length === 3 ? null : r.colors?.join(" or ");
|
||||
const values = r.values?.join(", ");
|
||||
if (r.combine === "or") return `${colors} or ${values}`;
|
||||
return [colors, r.parity, values].filter(Boolean).join(" · ") || "all dice";
|
||||
}
|
||||
export const SKILLS = {
|
||||
manager: {
|
||||
name: "Equipment manager",
|
||||
dice: 6,
|
||||
draw: 4,
|
||||
keep: 2,
|
||||
page: 1,
|
||||
description: "Give your equipment to any teammate, even from a different location.",
|
||||
},
|
||||
survivalist: {
|
||||
name: "Survivalist",
|
||||
dice: 5,
|
||||
draw: 1,
|
||||
keep: 1,
|
||||
page: 2,
|
||||
description: "One additional reroll during the reroll phase.",
|
||||
},
|
||||
gatherer: {
|
||||
name: "Gatherer",
|
||||
dice: 6,
|
||||
draw: 1,
|
||||
keep: 1,
|
||||
page: 3,
|
||||
description: "Forfeit a reroll to collect a power bar. Spend it during a movement turn for +1.",
|
||||
},
|
||||
buddy: {
|
||||
name: "Buddy",
|
||||
dice: 6,
|
||||
draw: 1,
|
||||
keep: 1,
|
||||
page: 4,
|
||||
description: "Set aside one die during rerolls. Everyone can see it; it returns after this round.",
|
||||
},
|
||||
scout: {
|
||||
name: "Scout",
|
||||
dice: 5,
|
||||
draw: 2,
|
||||
keep: 2,
|
||||
page: 5,
|
||||
description: "Travel up to four spaces. A four-space journey allows no phase-three rerolls.",
|
||||
},
|
||||
tinkerer: {
|
||||
name: "Tinkerer",
|
||||
dice: 5,
|
||||
draw: 3,
|
||||
keep: 1,
|
||||
page: 6,
|
||||
description: "Use each equipment card twice. Discard it after its second use.",
|
||||
},
|
||||
} as const;
|
||||
export type Skill = keyof typeof SKILLS;
|
||||
export const EQUIPMENT = [
|
||||
{ id: "binoculars", name: "Binoculars", phases: [2], description: "Swap two empty land tiles." },
|
||||
{
|
||||
id: "flare",
|
||||
name: "Flare gun",
|
||||
phases: [4],
|
||||
description: "+3 to your movement value during your turn this round.",
|
||||
},
|
||||
{ id: "rope", name: "Rope", phases: [2, 4], description: "Move immediately to an adjacent land tile." },
|
||||
{ id: "shovel", name: "Shovel", phases: [4], description: "Turn one of your dice to any face." },
|
||||
{ id: "torch", name: "Torch", phases: [2], description: "Reroll any of your dice once." },
|
||||
{
|
||||
id: "knife",
|
||||
name: "Pocketknife",
|
||||
phases: [2, 4],
|
||||
description: "Copy an equipment card belonging to another player.",
|
||||
},
|
||||
{ id: "water", name: "Water flask", phases: [4], description: "Take up to two rerolls, or grant one to a teammate." },
|
||||
{
|
||||
id: "aid",
|
||||
name: "First aid kit",
|
||||
phases: [4],
|
||||
description: "Lose no stamina this round. You must still qualify to move.",
|
||||
},
|
||||
{ id: "radio", name: "Wireless", phases: [2, 4], description: "Reveal your dice until the end of this phase." },
|
||||
{ id: "tape", name: "Tape", phases: [4], description: "Turn any of your ones to sixes." },
|
||||
{
|
||||
id: "machete",
|
||||
name: "Machete",
|
||||
phases: [4],
|
||||
description: "Set aside up to two dice, visible to everyone, until the end of this round.",
|
||||
},
|
||||
{
|
||||
id: "lighter",
|
||||
name: "Fire lighter",
|
||||
phases: [4],
|
||||
description: "Ask a teammate to lend you one die for this round.",
|
||||
},
|
||||
{ id: "carabiner", name: "Carabiner", phases: [4], description: "Every player must reroll exactly one die." },
|
||||
{ id: "compass", name: "Compass", phases: [4], description: "Turn any of your sixes to ones." },
|
||||
{ id: "map", name: "Map", phases: [4], description: "Lend one die to a teammate until the end of this round." },
|
||||
] as const;
|
||||
export type EquipmentId = (typeof EQUIPMENT)[number]["id"];
|
||||
export const equipment = (id: EquipmentId) => EQUIPMENT.find((c) => c.id === id)!;
|
||||
export const INJURIES = ["leg", "arm", "eye", "amnesia"] as const;
|
||||
export type Injury = (typeof INJURIES)[number];
|
||||
export const INJURY_AT = [5, 10, 15, 20];
|
||||
export const EXHAUSTION = 25;
|
||||
export const CHARACTERS = ["Mr Iain Jones", "Lady Livingstone", "Hiromi", "Kurt von Krach"];
|
||||
export const CHARACTER_COLORS = ["#dcb986", "#8acd90", "#88c6df", "#da9bde"];
|
||||
// Coordinates transcribed from scenario card 1. V4 is present only with four players.
|
||||
export const SCENARIO_ONE = [
|
||||
["V", " ", " ", " ", "v", "v", "v", "V4"],
|
||||
["R", " ", " ", " ", "vE", " ", " ", " "],
|
||||
["R", "S4", "E", "L", "v", "X", "E", " "],
|
||||
["S", "L", " ", "L", " ", "L", " ", " "],
|
||||
[" ", "L", "L", "L", "X", "L", "E", " "],
|
||||
[" ", "E", " ", " ", "L", " ", "L", " "],
|
||||
[" ", " ", " ", " ", "E", "L", "E", " "],
|
||||
];
|
||||
310
packages/engine/src/game.spec.ts
Normal file
|
|
@ -0,0 +1,310 @@
|
|||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import {
|
||||
initGame,
|
||||
applyMove,
|
||||
stripSecret,
|
||||
comparison,
|
||||
cell,
|
||||
terrain,
|
||||
paths,
|
||||
rerollAllowance,
|
||||
face,
|
||||
matches,
|
||||
replay,
|
||||
threatened,
|
||||
activePlayers,
|
||||
} from "../index.js";
|
||||
import type { State, Move } from "./types.js";
|
||||
function prepared(players = 3) {
|
||||
let s = initGame(players, {}, "test-seed");
|
||||
for (let i = 0; i < players; i++) {
|
||||
const p = s.players[i]!;
|
||||
const keep = p.cards.slice(0, p.skill === "manager" ? 2 : 1).map((c) => c.id);
|
||||
s = applyMove(s, { action: "setup", keep, drop: p.dice.at(-1)?.id }, i);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
function withPhase(phase: State["phase"] = "equipment") {
|
||||
const s = prepared();
|
||||
s.phase = phase;
|
||||
s.players.forEach((p) => (p.ready = false));
|
||||
return s;
|
||||
}
|
||||
function equip(s: State, seat: number, id: string, extra: Record<string, unknown> = {}) {
|
||||
s.players[seat]!.cards = [{ id: id as never, used: 0, availableRound: 0 }];
|
||||
return applyMove(s, { action: "equipment", id, ...extra }, seat);
|
||||
}
|
||||
test("scenario 1 includes exactly 21 landscape locations and player-count village slot", () => {
|
||||
const a = initGame(3),
|
||||
b = initGame(4);
|
||||
assert.equal(a.board.filter((c) => terrain(c.terrain).kind === "land").length, 21);
|
||||
assert.equal(a.board.filter((c) => terrain(c.terrain).kind === "village").length, 5);
|
||||
assert.equal(b.board.filter((c) => terrain(c.terrain).kind === "village").length, 6);
|
||||
assert.equal(b.players[2]!.position, "1,2");
|
||||
assert.equal(new Set(a.board.map((c) => c.terrain)).size, a.board.length);
|
||||
});
|
||||
test("seeded setup, rolls and JSON round trips are deterministic", () => {
|
||||
assert.deepEqual(prepared(), prepared());
|
||||
let a = withPhase("reroll");
|
||||
a.players[0]!.rerolls = 1;
|
||||
let b = JSON.parse(JSON.stringify(a));
|
||||
const move = { action: "reroll", ids: [a.players[0]!.dice[0]!.id] };
|
||||
assert.deepEqual(applyMove(a, move, 0), applyMove(b, move, 0));
|
||||
});
|
||||
test("invalid moves never mutate input, consume randomness or append logs", () => {
|
||||
const s = prepared(),
|
||||
before = structuredClone(s);
|
||||
assert.throws(() => applyMove(s, { action: "plan", path: ["0,3", "7,0"] }, 0));
|
||||
assert.deepEqual(s, before);
|
||||
assert.throws(() => applyMove(s, { action: "reroll", ids: ["0-0"] }, 0));
|
||||
assert.deepEqual(s, before);
|
||||
assert.throws(() => applyMove(s, { action: "ready" }, 12));
|
||||
});
|
||||
test("requirements use union for colour OR value, intersection for colour AND parity", () => {
|
||||
assert(matches({ color: "blue", value: 6 }, { colors: ["yellow"], values: [6], combine: "or" }));
|
||||
assert(matches({ color: "yellow", value: 6 }, { colors: ["yellow"], values: [6], combine: "or" }));
|
||||
assert(!matches({ color: "pink", value: 4 }, { colors: ["blue"], parity: "even" }));
|
||||
assert(matches({ color: "blue", value: 4 }, { colors: ["blue"], parity: "even" }));
|
||||
assert(!matches({ color: "blue", value: 3 }, { colors: ["blue"], parity: "even" }));
|
||||
});
|
||||
test("private projection removes seed, RNG, deck order and move history at every phase", () => {
|
||||
for (const phase of ["planning", "reroll", "equipment"] as const) {
|
||||
const s = withPhase(phase);
|
||||
const v = stripSecret(s, 0);
|
||||
assert(!("seed" in v));
|
||||
assert(!("counter" in v));
|
||||
assert(!("history" in v));
|
||||
assert(!("deck" in v));
|
||||
assert(!("initOptions" in v));
|
||||
assert(v.players[0]!.dice.every((d) => d.face > 0));
|
||||
assert(v.players[1]!.dice.every((d) => d.face === 0));
|
||||
assert(stripSecret(s).players.every((p) => p.dice.every((d) => !d.face)));
|
||||
assert(s.players[1]!.dice.every((d) => d.face > 0));
|
||||
}
|
||||
});
|
||||
test("wireless and set-aside dice reveal only intended information", () => {
|
||||
let s = withPhase();
|
||||
s.players[1]!.dice[0]!.aside = true;
|
||||
s = equip(s, 2, "radio");
|
||||
const v = stripSecret(s, 0);
|
||||
assert(v.players[1]!.dice[0]!.face > 0);
|
||||
assert(v.players[1]!.dice.slice(1).every((d) => !d.face));
|
||||
assert(v.players[2]!.dice.every((d) => d.face > 0));
|
||||
});
|
||||
test("two-player neutral set has three visible and three hidden dice", () => {
|
||||
const s = prepared(2),
|
||||
v = stripSecret(s, 0);
|
||||
assert.equal(v.ghost.filter((d) => d.face).length, 3);
|
||||
s.phase = "movement";
|
||||
assert.equal(stripSecret(s, 0).ghost.filter((d) => d.face).length, 6);
|
||||
assert.equal(comparison(s, 0).peers.length, 2);
|
||||
});
|
||||
test("no route crosses rubble or moves diagonally; movement length affects rerolls", () => {
|
||||
const s = prepared();
|
||||
assert(!paths(s, 0)["0,2"]);
|
||||
assert.equal(rerollAllowance(s, 0, ["0,3"]), 2 + (terrain(cell(s, "0,3").terrain).reroll ? 1 : 0));
|
||||
assert.throws(() => applyMove(s, { action: "plan", path: ["0,3", "1,4"] }, 0));
|
||||
});
|
||||
test("neighbors cannot confirm the same destination", () => {
|
||||
let s = prepared();
|
||||
s = applyMove(s, { action: "ready" }, 0);
|
||||
assert.throws(() => applyMove(s, { action: "ready" }, 1), /different destinations/);
|
||||
});
|
||||
test("comparison is strict; ties fail and cost maximum stamina", () => {
|
||||
const s = withPhase("movement");
|
||||
s.board.find((c) => c.id === "0,3")!.terrain = 16;
|
||||
s.players.forEach((p) => p.dice.forEach((d) => (d.face = 2)));
|
||||
assert.equal(comparison(s, 0).success, false);
|
||||
assert.equal(comparison(s, 0).loss, 3);
|
||||
s.players[0]!.dice[0]!.face = 3;
|
||||
assert.equal(comparison(s, 0).success, true);
|
||||
assert.equal(comparison(s, 0).loss, 2);
|
||||
s.players[0]!.aid = true;
|
||||
assert.equal(comparison(s, 0).loss, 0);
|
||||
});
|
||||
test("eruption propagates one wave, including rubble; no recursive flood in one action", () => {
|
||||
const s = withPhase("eruption");
|
||||
const next = threatened(s);
|
||||
assert.deepEqual(next, ["0,1"]);
|
||||
const a = applyMove(s, { action: "erupt" }, 0);
|
||||
assert(cell(a, "0,1").lava);
|
||||
assert(!cell(a, "0,2").lava);
|
||||
assert.equal(a.round, 2);
|
||||
assert.equal(a.phase, "planning");
|
||||
});
|
||||
test("eruption ends the game immediately if any player is caught", () => {
|
||||
const s = withPhase("eruption");
|
||||
cell(s, "0,2").lava = true;
|
||||
const a = applyMove(s, { action: "erupt" }, 0);
|
||||
assert.equal(a.outcome, "lost");
|
||||
assert.equal(a.phase, "ended");
|
||||
});
|
||||
test("win occurs as soon as everyone reaches village, before stamina or eruption", () => {
|
||||
const s = withPhase("movement");
|
||||
const v = s.board.find((c) => terrain(c.terrain).kind === "village")!;
|
||||
v.terrain = 16;
|
||||
v.terrain = 28;
|
||||
s.players.forEach((p) => {
|
||||
p.position = v.id;
|
||||
p.path = [v.id];
|
||||
});
|
||||
s.players[0]!.stamina = 24;
|
||||
s.players[0]!.bonus = 100;
|
||||
s.activeResolution = 0;
|
||||
const a = applyMove(s, { action: "resolve" }, 0);
|
||||
assert.equal(a.outcome, "won");
|
||||
assert.equal(a.players[0]!.stamina, 24);
|
||||
});
|
||||
test("leg injury removes a die only after all movement comparisons", () => {
|
||||
const s = withPhase("movement");
|
||||
s.activeResolution = 0;
|
||||
s.players[0]!.pendingInjuries = 1;
|
||||
s.players[0]!.resolved = true;
|
||||
const id = s.players[0]!.dice[0]!.id;
|
||||
let a = applyMove(s, { action: "injury", injury: "leg", die: id }, 0);
|
||||
assert.equal(a.players[0]!.dice.length, 6);
|
||||
assert(a.players[0]!.dice[0]!.remove);
|
||||
a.players.forEach((p) => (p.resolved = true));
|
||||
a.phase = "eruption";
|
||||
a = applyMove(a, { action: "erupt" }, 0);
|
||||
assert.equal(a.players[0]!.dice.length, 5);
|
||||
});
|
||||
test("a borrowed die returns to its owner after the round", () => {
|
||||
let s = withPhase();
|
||||
const id = s.players[0]!.dice[0]!.id;
|
||||
s = equip(s, 0, "map", { target: 1, ids: [id] });
|
||||
assert.equal(s.players[0]!.dice.length, 5);
|
||||
assert(s.players[1]!.dice.some((d) => d.id === id));
|
||||
s.phase = "eruption";
|
||||
s = applyMove(s, { action: "erupt" }, 0);
|
||||
assert(s.players[0]!.dice.some((d) => d.id === id));
|
||||
assert.equal(s.players[1]!.dice.length, 6);
|
||||
});
|
||||
test("lighter waits for donor consent instead of choosing a hidden die", () => {
|
||||
let s = withPhase();
|
||||
s = equip(s, 0, "lighter", { target: 1 });
|
||||
assert.deepEqual(activePlayers(s), [1]);
|
||||
assert.throws(() => applyMove(s, { action: "respond", ids: [s.players[1]!.dice[0]!.id] }, 0));
|
||||
s = applyMove(s, { action: "decline" }, 1);
|
||||
assert.equal(s.pending, null);
|
||||
assert.equal(s.players[0]!.dice.length, 6);
|
||||
});
|
||||
test("carabiner requires exactly one die from every player", () => {
|
||||
let s = equip(withPhase(), 0, "carabiner");
|
||||
assert.throws(() => applyMove(s, { action: "decline" }, 0));
|
||||
assert.throws(() => applyMove(s, { action: "respond", ids: [] }, 0));
|
||||
for (let i = 0; i < 3; i++) s = applyMove(s, { action: "respond", ids: [s.players[i]!.dice[0]!.id] }, i);
|
||||
assert.equal(s.pending, null);
|
||||
});
|
||||
test("water permits two distinct reroll choices and early stopping", () => {
|
||||
let s = equip(withPhase(), 0, "water", { target: 0 });
|
||||
s = applyMove(s, { action: "respond", ids: [s.players[0]!.dice[0]!.id] }, 0);
|
||||
assert.equal(s.pending?.remaining, 1);
|
||||
s = applyMove(s, { action: "decline" }, 0);
|
||||
assert.equal(s.pending, null);
|
||||
});
|
||||
test("gatherer caps stored bars and applies them only to active movement total", () => {
|
||||
let s = withPhase("reroll");
|
||||
s.players[1]!.powerBars = 2;
|
||||
s.players[1]!.rerolls = 3;
|
||||
s = applyMove(s, { action: "finishRerolls" }, 1);
|
||||
assert.equal(s.players[1]!.powerBars, 3);
|
||||
s.phase = "movement";
|
||||
s.activeResolution = 0;
|
||||
const before = comparison(s, 0).own;
|
||||
s = applyMove(s, { action: "bar" }, 1);
|
||||
assert.equal(comparison(s, 0).own, before + 1);
|
||||
assert.equal(s.players[1]!.bonus, 0);
|
||||
});
|
||||
test("tinkerer gets two uses; amnesia discards partially used equipment", () => {
|
||||
let s = withPhase();
|
||||
s.players[0]!.skill = "tinkerer";
|
||||
s = equip(s, 0, "aid");
|
||||
assert.equal(s.players[0]!.cards[0]!.used, 1);
|
||||
s.phase = "movement";
|
||||
s.players[0]!.pendingInjuries = 1;
|
||||
s = applyMove(s, { action: "injury", injury: "amnesia" }, 0);
|
||||
assert.equal(s.players[0]!.cards.length, 0);
|
||||
assert(s.discard.includes("aid"));
|
||||
});
|
||||
test("replay reconstructs setup and planning without divergence", () => {
|
||||
let s = prepared();
|
||||
s = applyMove(s, { action: "plan", path: ["0,3", "1,3"] }, 0);
|
||||
assert.deepEqual(replay(s), s);
|
||||
});
|
||||
test("all color-changing equipment preserves the inferred die type", () => {
|
||||
let s = withPhase();
|
||||
s.players[0]!.dice.forEach((d) => (d.face = 1));
|
||||
const ids = s.players[0]!.dice.map((d) => d.id);
|
||||
const colors = s.players[0]!.dice.map((d) => face(d).color);
|
||||
s = equip(s, 0, "tape", { ids });
|
||||
assert(s.players[0]!.dice.every((d) => d.face === 6));
|
||||
assert.deepEqual(
|
||||
s.players[0]!.dice.map((d) => face(d).color),
|
||||
colors
|
||||
);
|
||||
s = equip(s, 0, "compass", { ids });
|
||||
assert(s.players[0]!.dice.every((d) => d.face === 1));
|
||||
s = equip(s, 0, "shovel", { ids: [ids[0]], face: 3 });
|
||||
assert.equal(s.players[0]!.dice[0]!.face, 3);
|
||||
assert.equal(face(s.players[0]!.dice[0]!).color, "pink");
|
||||
});
|
||||
test("binoculars swap only completely empty landscape cards", () => {
|
||||
let s = withPhase("planning");
|
||||
const available = s.board.filter(
|
||||
(c) =>
|
||||
!c.lava &&
|
||||
!c.equipment &&
|
||||
!c.eruption &&
|
||||
terrain(c.terrain).kind === "land" &&
|
||||
!s.players.some((p) => p.position === c.id)
|
||||
);
|
||||
const a = available[0]!,
|
||||
b = available[1]!;
|
||||
const before = [a.terrain, b.terrain];
|
||||
s = equip(s, 0, "binoculars", { tiles: [a.id, b.id] });
|
||||
assert.deepEqual([cell(s, a.id).terrain, cell(s, b.id).terrain], before.reverse());
|
||||
assert.throws(() => equip(s, 0, "binoculars", { tiles: [s.players[0]!.position, b.id] }));
|
||||
});
|
||||
test("rope moves immediately and keeps equipment found unavailable until the next round", () => {
|
||||
let s = withPhase("planning");
|
||||
const destination = cell(s, "1,3");
|
||||
destination.equipment = true;
|
||||
const before = s.players[0]!.cards.length;
|
||||
s = equip(s, 0, "rope", { tiles: [destination.id] });
|
||||
assert.equal(s.players[0]!.position, destination.id);
|
||||
assert.equal(cell(s, destination.id).equipment, false);
|
||||
assert(s.players[0]!.cards.some((c) => c.availableRound === s.round + 1));
|
||||
});
|
||||
test("pocketknife copies without consuming the original equipment", () => {
|
||||
let s = withPhase();
|
||||
s.players[1]!.cards = [{ id: "aid", used: 0, availableRound: 0 }];
|
||||
s = equip(s, 0, "knife", { copy: "aid" });
|
||||
assert(s.players[0]!.aid);
|
||||
assert(s.players[1]!.cards.some((c) => c.id === "aid"));
|
||||
assert(!s.players[0]!.cards.length);
|
||||
});
|
||||
test("eye injury retains Survivalist bonus; Scout four-step route has no rerolls", () => {
|
||||
const s = prepared();
|
||||
s.players[0]!.skill = "survivalist";
|
||||
s.players[0]!.injuries = ["eye"];
|
||||
assert.equal(rerollAllowance(s, 0), 1);
|
||||
s.players[0]!.skill = "scout";
|
||||
s.players[0]!.injuries = [];
|
||||
assert.equal(rerollAllowance(s, 0, ["0,3", "1,3", "1,4", "2,4", "3,4"]), 0);
|
||||
});
|
||||
test("readiness can be revised before simultaneous planning closes", () => {
|
||||
let s = prepared();
|
||||
s = applyMove(s, { action: "ready" }, 0);
|
||||
assert(activePlayers(s).includes(0));
|
||||
s = applyMove(s, { action: "plan", path: ["0,3", "1,3"] }, 0);
|
||||
assert(!s.players[0]!.ready);
|
||||
});
|
||||
test("metadata and player drops replay exactly without exposing system actions to players", async () => {
|
||||
const { setPlayerName, dropGamePlayer } = await import("./game.js");
|
||||
let s = setPlayerName(prepared(), 0, "Alice");
|
||||
s = dropGamePlayer(s, 1);
|
||||
assert.deepEqual(replay(s), s);
|
||||
assert.throws(() => applyMove(prepared(), { action: "$drop" }, 0));
|
||||
});
|
||||
718
packages/engine/src/game.ts
Normal file
|
|
@ -0,0 +1,718 @@
|
|||
import seedrandom from "seedrandom";
|
||||
import {
|
||||
DICE,
|
||||
EQUIPMENT,
|
||||
EXHAUSTION,
|
||||
INJURIES,
|
||||
INJURY_AT,
|
||||
SCENARIO_ONE,
|
||||
SKILLS,
|
||||
CHARACTERS,
|
||||
terrain,
|
||||
matches,
|
||||
equipment,
|
||||
type Skill,
|
||||
type EquipmentId,
|
||||
type Injury,
|
||||
} from "./data.js";
|
||||
import type { State, View, Player, Die, Cell, Move, ResolvedFace } from "./types.js";
|
||||
export const assert = (ok: unknown, message: string): asserts ok => {
|
||||
if (!ok) throw Error(message);
|
||||
};
|
||||
export function face(d: Die): ResolvedFace {
|
||||
return { value: d.face, color: DICE[d.type]?.[d.face - 1] ?? "blue" };
|
||||
}
|
||||
function random(s: State): number {
|
||||
return seedrandom(`${s.seed}:${s.counter++}`)();
|
||||
}
|
||||
function shuffle<T>(s: State, items: T[]): T[] {
|
||||
const a = [...items];
|
||||
for (let i = a.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(random(s) * (i + 1));
|
||||
[a[i], a[j]] = [a[j]!, a[i]!];
|
||||
}
|
||||
return a;
|
||||
}
|
||||
function roll(s: State, dice: Die[]) {
|
||||
for (const d of dice) d.face = 1 + Math.floor(random(s) * 6);
|
||||
}
|
||||
export function cell(s: State | View, id: string): Cell {
|
||||
const c = s.board.find((c) => c.id === id);
|
||||
if (!c) throw Error("Unknown location");
|
||||
return c;
|
||||
}
|
||||
export function neighbors(s: State | View, seat: number): number[] {
|
||||
const n = s.players.length;
|
||||
return [...new Set([(seat + n - 1) % n, (seat + 1) % n])];
|
||||
}
|
||||
export function hasSkill(p: Player, skill: Skill) {
|
||||
return p.skill === skill && !p.injuries.includes("amnesia");
|
||||
}
|
||||
export function activeDice(p: Player) {
|
||||
return p.dice.filter((d) => !d.aside);
|
||||
}
|
||||
export function distance(a: Cell, b: Cell) {
|
||||
return Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
|
||||
}
|
||||
export function walkable(c: Cell) {
|
||||
return !c.lava && !["rubble", "volcano"].includes(terrain(c.terrain).kind);
|
||||
}
|
||||
export function paths(s: State | View, seat: number, max?: number): Record<string, string[]> {
|
||||
const p = s.players[seat];
|
||||
if (!p) return {};
|
||||
const limit = max ?? (hasSkill(p, "scout") ? 4 : 3);
|
||||
const found: Record<string, string[]> = { [p.position]: [p.position] };
|
||||
const queue = [found[p.position]!];
|
||||
while (queue.length) {
|
||||
const path = queue.shift()!;
|
||||
if (path.length - 1 >= limit) continue;
|
||||
const last = cell(s, path.at(-1)!);
|
||||
for (const next of s.board.filter((c) => walkable(c) && distance(last, c) === 1)) {
|
||||
if (found[next.id]) continue;
|
||||
found[next.id] = [...path, next.id];
|
||||
queue.push(found[next.id]!);
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
export function rerollAllowance(s: State | View, seat: number, path?: string[]): number {
|
||||
const p = s.players[seat]!;
|
||||
const chosen = path ?? p.path;
|
||||
const dist = chosen.length - 1;
|
||||
if (hasSkill(p, "scout") && dist === 4) return 0;
|
||||
const base = p.injuries.includes("eye")
|
||||
? 0
|
||||
: (dist === 0 ? 2 : dist <= 2 ? 1 : 0) + (terrain(cell(s, chosen.at(-1)!).terrain).reroll ? 1 : 0);
|
||||
return base + (hasSkill(p, "survivalist") ? 1 : 0);
|
||||
}
|
||||
export function total(p: Player, tile: number): number {
|
||||
return activeDice(p).reduce((n, d) => n + (matches(face(d), terrain(tile).requirement) ? d.face : 0), 0);
|
||||
}
|
||||
export function comparison(s: State | View, seat: number) {
|
||||
const p = s.players[seat]!;
|
||||
const tile = cell(s, p.path.at(-1) ?? p.position).terrain;
|
||||
const own = total(p, tile) + p.bonus;
|
||||
const peers = neighbors(s, seat).map((i) => ({ seat: i, total: total(s.players[i]!, tile) }));
|
||||
if (s.players.length === 2)
|
||||
peers.push({
|
||||
seat: -1,
|
||||
total: s.ghost.reduce((n, d) => n + (matches(face(d), terrain(tile).requirement) ? d.face : 0), 0),
|
||||
});
|
||||
const highest = Math.max(...peers.map((p) => p.total));
|
||||
const margin = own - highest;
|
||||
const loss = p.aid ? 0 : margin <= 0 ? s.difficulty + 2 : Math.max(0, s.difficulty + 2 - Math.ceil(margin / 2));
|
||||
return { own, peers, margin, loss, success: margin > 0 };
|
||||
}
|
||||
function event(s: State, text: string, type: State["log"][number]["type"] = "move") {
|
||||
s.log.push({ round: s.round, text, type });
|
||||
}
|
||||
function phase(s: State, next: State["phase"]) {
|
||||
s.phase = next;
|
||||
for (const p of s.players) {
|
||||
p.ready = false;
|
||||
p.radio = false;
|
||||
}
|
||||
event(
|
||||
s,
|
||||
{
|
||||
setup: "Prepare your expedition",
|
||||
planning: "Choose your routes",
|
||||
reroll: "Reroll in silence",
|
||||
equipment: "Use equipment",
|
||||
movement: "Reveal and move",
|
||||
eruption: "The volcano erupts",
|
||||
ended: "Expedition complete",
|
||||
}[next],
|
||||
"phase"
|
||||
);
|
||||
}
|
||||
function end(s: State, outcome: "won" | "lost", reason: string) {
|
||||
s.outcome = outcome;
|
||||
s.reason = reason;
|
||||
s.phase = "ended";
|
||||
s.pending = null;
|
||||
event(s, reason, "end");
|
||||
}
|
||||
function win(s: State) {
|
||||
if (s.players.every((p) => terrain(cell(s, p.position).terrain).kind === "village"))
|
||||
end(s, "won", "Everyone reached the village.");
|
||||
}
|
||||
function draw(s: State, p: Player, availableRound = s.round + 1) {
|
||||
const id = s.deck.shift();
|
||||
if (id) p.cards.push({ id, used: 0, availableRound });
|
||||
}
|
||||
function collect(s: State, p: Player) {
|
||||
const c = cell(s, p.position);
|
||||
if (c.equipment) {
|
||||
c.equipment = false;
|
||||
draw(s, p);
|
||||
event(s, `${p.name} found equipment.`, "equipment");
|
||||
}
|
||||
}
|
||||
export function threatened(s: State | View): string[] {
|
||||
return s.board.filter((c) => !c.lava && s.board.some((l) => l.lava && distance(c, l) === 1)).map((c) => c.id);
|
||||
}
|
||||
function erupt(s: State) {
|
||||
const next = threatened(s);
|
||||
for (const c of s.board) if (next.includes(c.id)) c.lava = true;
|
||||
event(s, `Lava consumed ${next.length} location${next.length === 1 ? "" : "s"}.`, "eruption");
|
||||
const victim = s.players.find((p) => cell(s, p.position).lava);
|
||||
if (victim) end(s, "lost", `${victim.name} was caught by the lava.`);
|
||||
}
|
||||
function trigger(s: State, path: string[]) {
|
||||
for (const id of path) {
|
||||
const c = cell(s, id);
|
||||
const count = c.eruption;
|
||||
c.eruption = 0;
|
||||
for (let i = 0; i < count && !s.outcome; i++) erupt(s);
|
||||
}
|
||||
}
|
||||
function startRound(s: State) {
|
||||
s.round++;
|
||||
s.activeResolution = null;
|
||||
s.pending = null;
|
||||
const all = s.players.flatMap((p) => p.dice).filter((d) => !d.remove);
|
||||
for (let i = 0; i < s.players.length; i++) {
|
||||
const p = s.players[i]!;
|
||||
p.dice = all.filter((d) => d.owner === i);
|
||||
for (const d of p.dice) d.aside = false;
|
||||
p.path = [p.position];
|
||||
p.resolved = false;
|
||||
p.buddyUsed = false;
|
||||
p.aid = false;
|
||||
p.bonus = 0;
|
||||
p.rerolls = 0;
|
||||
roll(s, p.dice);
|
||||
}
|
||||
roll(s, s.ghost);
|
||||
phase(s, "planning");
|
||||
}
|
||||
export function initGame(players = 3, options: Record<string, unknown> = {}, seed = "fuji"): State {
|
||||
if (!Number.isInteger(players) || players < 2 || players > 4) throw Error("Fuji supports 2–4 players.");
|
||||
const difficulty = Number(options.difficulty ?? 1);
|
||||
if (!Number.isInteger(difficulty) || difficulty < 1 || difficulty > 4) throw Error("Choose difficulty 1–4.");
|
||||
if (options.scenario !== undefined && Number(options.scenario) !== 1)
|
||||
throw Error("This edition currently implements scenario 1.");
|
||||
const s: State = {
|
||||
schemaVersion: 1,
|
||||
seed,
|
||||
counter: 0,
|
||||
round: 0,
|
||||
phase: "setup",
|
||||
players: [],
|
||||
board: [],
|
||||
deck: [],
|
||||
discard: [],
|
||||
difficulty,
|
||||
log: [],
|
||||
revision: 0,
|
||||
outcome: null,
|
||||
reason: "",
|
||||
activeResolution: null,
|
||||
pending: null,
|
||||
ghost: [],
|
||||
ghostVisible: [],
|
||||
history: [],
|
||||
initOptions: { ...options },
|
||||
};
|
||||
const lands = shuffle(
|
||||
s,
|
||||
Array.from({ length: 24 }, (_, i) => i + 4)
|
||||
);
|
||||
const villages = shuffle(s, [28, 29, 30, 31, 32, 33]);
|
||||
let rubble = 2;
|
||||
SCENARIO_ONE.forEach((row, y) =>
|
||||
row.forEach((code, x) => {
|
||||
if (code === " " || (code === "V4" && players !== 4)) return;
|
||||
const village = code.startsWith("v") || code === "V4";
|
||||
const id = code === "V" ? 1 : code === "R" ? rubble++ : village ? villages.shift()! : lands.shift()!;
|
||||
s.board.push({
|
||||
id: `${x},${y}`,
|
||||
x,
|
||||
y,
|
||||
terrain: id,
|
||||
lava: code === "V",
|
||||
equipment: code.includes("E"),
|
||||
eruption: code === "X" ? 1 : 0,
|
||||
});
|
||||
})
|
||||
);
|
||||
s.deck = shuffle(
|
||||
s,
|
||||
EQUIPMENT.map((c) => c.id)
|
||||
);
|
||||
const skillList: Skill[] = Array.isArray(options.skills)
|
||||
? (options.skills as Skill[])
|
||||
: (["buddy", "gatherer", "manager", "survivalist"] as Skill[]);
|
||||
if (skillList.length < players || skillList.some((x) => !(x in SKILLS))) throw Error("Invalid skill selection.");
|
||||
for (let i = 0; i < players; i++) {
|
||||
const skill = skillList[i]!;
|
||||
const pos = players === 4 && i >= 2 ? "1,2" : "0,3";
|
||||
const p: Player = {
|
||||
name: CHARACTERS[i]!,
|
||||
character: i,
|
||||
skill,
|
||||
position: pos,
|
||||
path: [pos],
|
||||
dice: Array.from({ length: 6 }, (_, j) => ({
|
||||
id: `${i}-${j}`,
|
||||
type: Math.floor(j / 2),
|
||||
owner: i,
|
||||
face: 0,
|
||||
aside: false,
|
||||
remove: false,
|
||||
})),
|
||||
cards: [],
|
||||
stamina: 0,
|
||||
injuries: [],
|
||||
pendingInjuries: 0,
|
||||
ready: false,
|
||||
rerolls: 0,
|
||||
powerBars: 0,
|
||||
radio: false,
|
||||
aid: false,
|
||||
bonus: 0,
|
||||
resolved: false,
|
||||
setupDone: false,
|
||||
buddyUsed: false,
|
||||
};
|
||||
for (let j = 0; j < SKILLS[skill].draw; j++) draw(s, p, 1);
|
||||
s.players.push(p);
|
||||
}
|
||||
if (players === 2) {
|
||||
s.ghost = Array.from({ length: 6 }, (_, j) => ({
|
||||
id: `ghost-${j}`,
|
||||
type: Math.floor(j / 2),
|
||||
owner: -1,
|
||||
face: 0,
|
||||
aside: false,
|
||||
remove: false,
|
||||
}));
|
||||
s.ghostVisible = s.ghost.filter((_, j) => j % 2 === 0).map((d) => d.id);
|
||||
}
|
||||
event(s, "Scenario 1 · the path to the village", "phase");
|
||||
return s;
|
||||
}
|
||||
function strings(value: unknown, max = 6): string[] {
|
||||
if (
|
||||
!Array.isArray(value) ||
|
||||
value.length > max ||
|
||||
value.some((x) => typeof x !== "string") ||
|
||||
new Set(value).size !== value.length
|
||||
)
|
||||
throw Error("Invalid selection.");
|
||||
return [...value] as string[];
|
||||
}
|
||||
function integer(value: unknown, min: number, max: number) {
|
||||
if (typeof value !== "number" || !Number.isInteger(value) || value < min || value > max)
|
||||
throw Error("Invalid choice.");
|
||||
return value;
|
||||
}
|
||||
function selectedDice(p: Player, value: unknown, min = 0, max = 6): Die[] {
|
||||
const ids = strings(value, max);
|
||||
if (ids.length < min) throw Error("Select a die.");
|
||||
return ids.map((id) => {
|
||||
const d = p.dice.find((d) => d.id === id && !d.aside);
|
||||
if (!d) throw Error("This die is unavailable.");
|
||||
return d;
|
||||
});
|
||||
}
|
||||
function validatePath(s: State, p: Player, input: unknown, max: number) {
|
||||
const route = strings(input, 5);
|
||||
if (!route.length || route[0] !== p.position || route.length - 1 > max) throw Error("Choose a reachable route.");
|
||||
for (let i = 1; i < route.length; i++) {
|
||||
if (!walkable(cell(s, route[i]!)) || distance(cell(s, route[i - 1]!), cell(s, route[i]!)) !== 1)
|
||||
throw Error("The route must follow adjacent safe locations.");
|
||||
}
|
||||
return route;
|
||||
}
|
||||
function resetReady(s: State) {
|
||||
for (const p of s.players) p.ready = false;
|
||||
}
|
||||
function afterMovement(s: State) {
|
||||
if (s.outcome) return;
|
||||
if (s.players.some((p) => p.pendingInjuries)) return;
|
||||
s.activeResolution = null;
|
||||
if (s.players.every((p) => p.resolved)) phase(s, "eruption");
|
||||
}
|
||||
function finishPending(s: State) {
|
||||
if (s.pending?.players.length === 0) s.pending = null;
|
||||
}
|
||||
function useEquipment(s: State, seat: number, m: Move) {
|
||||
const p = s.players[seat]!;
|
||||
if (s.phase !== "planning" && s.phase !== "equipment") throw Error("Equipment cannot be used in this phase.");
|
||||
if (p.injuries.includes("arm")) throw Error("Your arm injury prevents equipment use.");
|
||||
const card = p.cards.find((c) => c.id === m.id);
|
||||
if (!card || card.availableRound > s.round) throw Error("This equipment is not available yet.");
|
||||
let id = card.id;
|
||||
if (id === "knife") {
|
||||
const copied = EQUIPMENT.find((c) => c.id === m.copy && c.id !== "knife");
|
||||
if (
|
||||
!copied ||
|
||||
!s.players.some(
|
||||
(other, i) => i !== seat && other.cards.some((c) => c.id === copied.id && c.availableRound <= s.round)
|
||||
)
|
||||
)
|
||||
throw Error("Choose another player’s available equipment.");
|
||||
id = copied.id;
|
||||
}
|
||||
const info = equipment(id);
|
||||
if (!(info.phases as readonly number[]).includes(s.phase === "planning" ? 2 : 4))
|
||||
throw Error("This equipment is not usable in this phase.");
|
||||
const target = () => integer(m.target, 0, s.players.length - 1);
|
||||
switch (id) {
|
||||
case "binoculars": {
|
||||
const ids = strings(m.tiles, 2);
|
||||
if (ids.length !== 2) throw Error("Choose two land locations.");
|
||||
const [a, b] = ids.map((id) => cell(s, id)) as [Cell, Cell];
|
||||
for (const c of [a, b])
|
||||
if (
|
||||
terrain(c.terrain).kind !== "land" ||
|
||||
c.lava ||
|
||||
c.equipment ||
|
||||
c.eruption ||
|
||||
s.players.some((p) => p.position === c.id || (p.path.length > 0 && p.path.at(-1) === c.id))
|
||||
)
|
||||
throw Error("Both land locations must be completely empty.");
|
||||
[a.terrain, b.terrain] = [b.terrain, a.terrain];
|
||||
break;
|
||||
}
|
||||
case "flare":
|
||||
p.bonus += 3;
|
||||
break;
|
||||
case "rope": {
|
||||
const ids = strings(m.tiles, 1);
|
||||
if (ids.length !== 1) throw Error("Choose an adjacent land location.");
|
||||
const c = cell(s, ids[0]!);
|
||||
if (!walkable(c) || terrain(c.terrain).kind !== "land" || distance(cell(s, p.position), c) !== 1)
|
||||
throw Error("Choose an adjacent land location.");
|
||||
p.position = c.id;
|
||||
collect(s, p);
|
||||
trigger(s, [c.id]);
|
||||
if (s.phase === "planning") {
|
||||
p.path = [p.position];
|
||||
}
|
||||
win(s);
|
||||
break;
|
||||
}
|
||||
case "shovel": {
|
||||
const d = selectedDice(p, m.ids, 1, 1)[0]!;
|
||||
d.face = integer(m.face, 1, 6);
|
||||
break;
|
||||
}
|
||||
case "torch":
|
||||
roll(s, selectedDice(p, m.ids, 1));
|
||||
break;
|
||||
case "water": {
|
||||
const recipient = target();
|
||||
s.pending = { kind: "reroll", players: [recipient], remaining: recipient === seat ? 2 : 1, required: false };
|
||||
break;
|
||||
}
|
||||
case "aid":
|
||||
p.aid = true;
|
||||
break;
|
||||
case "radio":
|
||||
p.radio = true;
|
||||
break;
|
||||
case "tape":
|
||||
case "compass": {
|
||||
const dice = selectedDice(p, m.ids, 1);
|
||||
const from = id === "tape" ? 1 : 6;
|
||||
if (dice.some((d) => d.face !== from)) throw Error(`Select dice showing ${from}.`);
|
||||
for (const d of dice) d.face = 7 - from;
|
||||
break;
|
||||
}
|
||||
case "machete":
|
||||
for (const d of selectedDice(p, m.ids, 1, 2)) d.aside = true;
|
||||
break;
|
||||
case "lighter": {
|
||||
const donor = target();
|
||||
if (donor === seat) throw Error("Choose a teammate.");
|
||||
s.pending = { kind: "lend", players: [donor], receiver: seat, remaining: 1, required: false };
|
||||
break;
|
||||
}
|
||||
case "carabiner":
|
||||
s.pending = { kind: "reroll", players: s.players.map((_, i) => i), remaining: 1, required: true };
|
||||
break;
|
||||
case "map": {
|
||||
const recipient = target();
|
||||
if (recipient === seat) throw Error("Choose a teammate.");
|
||||
const d = selectedDice(p, m.ids, 1, 1)[0]!;
|
||||
p.dice = p.dice.filter((x) => x.id !== d.id);
|
||||
s.players[recipient]!.dice.push(d);
|
||||
break;
|
||||
}
|
||||
}
|
||||
card.used++;
|
||||
if (!hasSkill(p, "tinkerer") || card.used >= 2) {
|
||||
p.cards = p.cards.filter((c) => c !== card);
|
||||
s.discard.push(card.id);
|
||||
}
|
||||
resetReady(s);
|
||||
event(s, `${p.name} used ${equipment(card.id).name}${id !== card.id ? ` as ${info.name}` : ""}.`, "equipment");
|
||||
}
|
||||
function execute(s: State, m: Move, seat: number) {
|
||||
if (s.outcome) throw Error("The expedition has ended.");
|
||||
const p = s.players[seat];
|
||||
if (!p) throw Error("Invalid player.");
|
||||
if (s.pending) {
|
||||
const pending = s.pending;
|
||||
if (!pending.players.includes(seat)) throw Error("Waiting for another player.");
|
||||
if (m.action === "decline") {
|
||||
if (pending.required) throw Error("This reroll is mandatory.");
|
||||
pending.players = pending.players.filter((i) => i !== seat);
|
||||
} else if (m.action === "respond") {
|
||||
const dice = selectedDice(p, m.ids, pending.required ? 1 : 0, pending.required ? 1 : 6);
|
||||
if (pending.kind === "lend") {
|
||||
if (dice.length !== 1) throw Error("Choose one die to lend.");
|
||||
const d = dice[0]!;
|
||||
p.dice = p.dice.filter((x) => x !== d);
|
||||
s.players[pending.receiver!]!.dice.push(d);
|
||||
pending.players = [];
|
||||
} else {
|
||||
roll(s, dice);
|
||||
pending.remaining--;
|
||||
if (pending.required || pending.remaining <= 0) pending.players = pending.players.filter((i) => i !== seat);
|
||||
}
|
||||
} else throw Error("Resolve the equipment effect first.");
|
||||
event(s, `${p.name} resolved an equipment effect.`, "equipment");
|
||||
finishPending(s);
|
||||
return;
|
||||
}
|
||||
if (s.players.some((p) => p.pendingInjuries) && m.action !== "injury") throw Error("Choose an injury first.");
|
||||
switch (m.action) {
|
||||
case "setup": {
|
||||
if (s.phase !== "setup" || p.setupDone) throw Error("Preparation is already complete.");
|
||||
const keep = strings(m.keep, 4);
|
||||
const spec = SKILLS[p.skill];
|
||||
if (keep.length !== spec.keep || keep.some((id) => !p.cards.some((c) => c.id === id)))
|
||||
throw Error(`Keep ${spec.keep} equipment card(s).`);
|
||||
if (spec.dice === 5) {
|
||||
const d = p.dice.find((d) => d.id === m.drop);
|
||||
if (!d) throw Error("Choose one die to leave behind.");
|
||||
p.dice = p.dice.filter((x) => x !== d);
|
||||
}
|
||||
const rest = p.cards.filter((c) => !keep.includes(c.id));
|
||||
p.cards = p.cards.filter((c) => keep.includes(c.id));
|
||||
s.deck.push(...rest.map((c) => c.id));
|
||||
p.setupDone = true;
|
||||
if (s.players.every((p) => p.setupDone)) startRound(s);
|
||||
break;
|
||||
}
|
||||
case "plan": {
|
||||
if (s.phase !== "planning") throw Error("Routes are locked for this round.");
|
||||
const route = validatePath(s, p, m.path, hasSkill(p, "scout") ? 4 : 3);
|
||||
if (neighbors(s, seat).some((i) => s.players[i]!.path.at(-1) === route.at(-1) && s.players[i]!.ready))
|
||||
throw Error("A neighbor has already selected that destination.");
|
||||
p.path = route;
|
||||
p.ready = false;
|
||||
event(s, `${p.name} is planning a route.`);
|
||||
break;
|
||||
}
|
||||
case "ready": {
|
||||
if (s.phase !== "planning" && s.phase !== "equipment") throw Error("You cannot confirm in this phase.");
|
||||
if (p.ready) throw Error("Already ready.");
|
||||
if (s.phase === "planning") {
|
||||
validatePath(s, p, p.path, hasSkill(p, "scout") ? 4 : 3);
|
||||
if (neighbors(s, seat).some((i) => s.players[i]!.ready && s.players[i]!.path.at(-1) === p.path.at(-1)))
|
||||
throw Error("Neighbors need different destinations.");
|
||||
}
|
||||
p.ready = true;
|
||||
event(s, `${p.name} is ready.`);
|
||||
if (s.players.every((p) => p.ready)) {
|
||||
if (s.phase === "planning") {
|
||||
phase(s, "reroll");
|
||||
s.players.forEach((p, i) => {
|
||||
p.rerolls = rerollAllowance(s, i);
|
||||
});
|
||||
} else phase(s, "movement");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "reroll": {
|
||||
if (s.phase !== "reroll" || p.ready || p.rerolls < 1) throw Error("No rerolls available.");
|
||||
const dice = selectedDice(p, m.ids, 1);
|
||||
roll(s, dice);
|
||||
p.rerolls--;
|
||||
event(s, `${p.name} rerolled.`);
|
||||
break;
|
||||
}
|
||||
case "finishRerolls": {
|
||||
if (s.phase !== "reroll" || p.ready) throw Error("Rerolls are already complete.");
|
||||
if (hasSkill(p, "gatherer")) p.powerBars = Math.min(3, p.powerBars + p.rerolls);
|
||||
p.rerolls = 0;
|
||||
p.ready = true;
|
||||
if (s.players.every((p) => p.ready)) phase(s, "equipment");
|
||||
break;
|
||||
}
|
||||
case "buddy": {
|
||||
if (s.phase !== "reroll" || p.ready || !hasSkill(p, "buddy") || p.buddyUsed)
|
||||
throw Error("This skill is unavailable.");
|
||||
selectedDice(p, m.ids, 1, 1)[0]!.aside = true;
|
||||
p.buddyUsed = true;
|
||||
event(s, `${p.name} set a die aside.`);
|
||||
break;
|
||||
}
|
||||
case "give": {
|
||||
if (!hasSkill(p, "manager")) throw Error("Only the Equipment manager can give equipment.");
|
||||
const target = integer(m.target, 0, s.players.length - 1);
|
||||
if (target === seat) throw Error("Choose a teammate.");
|
||||
const c = p.cards.find((c) => c.id === m.id);
|
||||
if (!c) throw Error("Unknown equipment.");
|
||||
p.cards = p.cards.filter((x) => x !== c);
|
||||
s.players[target]!.cards.push(c);
|
||||
if (s.phase === "planning" || s.phase === "equipment") resetReady(s);
|
||||
event(s, `${p.name} gave equipment to ${s.players[target]!.name}.`, "equipment");
|
||||
break;
|
||||
}
|
||||
case "equipment":
|
||||
useEquipment(s, seat, m);
|
||||
break;
|
||||
case "beginMovement": {
|
||||
if (s.phase !== "movement" || s.activeResolution !== null || p.resolved)
|
||||
throw Error("Choose an unresolved player to move.");
|
||||
s.activeResolution = seat;
|
||||
event(s, `${p.name} is resolving their journey.`);
|
||||
break;
|
||||
}
|
||||
case "bar": {
|
||||
if (s.phase !== "movement" || s.activeResolution === null || !hasSkill(p, "gatherer") || p.powerBars < 1)
|
||||
throw Error("No power bar is available now.");
|
||||
p.powerBars--;
|
||||
s.players[s.activeResolution]!.bonus++;
|
||||
event(s, `${p.name} used a power bar.`);
|
||||
break;
|
||||
}
|
||||
case "resolve": {
|
||||
if (s.phase !== "movement" || s.activeResolution !== seat || p.resolved)
|
||||
throw Error("It is not your movement turn.");
|
||||
const dest = p.path.at(-1)!;
|
||||
let route = p.path;
|
||||
if (route[0] !== p.position) route = paths(s, seat)[dest] ?? [];
|
||||
if (m.path !== undefined) {
|
||||
route = validatePath(s, p, m.path, hasSkill(p, "scout") ? 4 : 3);
|
||||
if (route.at(-1) !== dest) throw Error("Your destination cannot change.");
|
||||
}
|
||||
const result = comparison(s, seat);
|
||||
let canMove = result.success && route.length > 0;
|
||||
if (route.slice(1).some((id) => !walkable(cell(s, id)))) canMove = false;
|
||||
if (canMove) {
|
||||
p.position = dest;
|
||||
event(
|
||||
s,
|
||||
`${p.name} reached ${terrain(cell(s, dest).terrain).name} (${result.own} vs ${Math.max(...result.peers.map((x) => x.total))}).`
|
||||
);
|
||||
win(s);
|
||||
if (s.outcome) break;
|
||||
collect(s, p);
|
||||
trigger(s, route.slice(1));
|
||||
if (s.outcome) break;
|
||||
} else event(s, `${p.name} stayed in place (${result.own} vs ${Math.max(...result.peers.map((x) => x.total))}).`);
|
||||
const loss = p.aid ? 0 : canMove ? result.loss : s.difficulty + 2;
|
||||
const old = p.stamina;
|
||||
p.stamina = Math.min(EXHAUSTION, p.stamina + loss);
|
||||
p.pendingInjuries += INJURY_AT.filter((n) => n > old && n <= p.stamina).length;
|
||||
event(s, `${p.name} lost ${loss} stamina.`);
|
||||
p.resolved = true;
|
||||
if (p.stamina >= EXHAUSTION) end(s, "lost", `${p.name} collapsed from exhaustion.`);
|
||||
else afterMovement(s);
|
||||
break;
|
||||
}
|
||||
case "injury": {
|
||||
if (!p.pendingInjuries || !INJURIES.includes(m.injury as Injury) || p.injuries.includes(m.injury as Injury))
|
||||
throw Error("Choose a new injury.");
|
||||
const injury = m.injury as Injury;
|
||||
if (injury === "leg") {
|
||||
const d = s.players.flatMap((p) => p.dice).find((d) => d.id === m.die);
|
||||
if (!d || d.owner !== seat || d.remove) throw Error("Choose one of your own dice.");
|
||||
d.remove = true;
|
||||
}
|
||||
if (injury === "amnesia" && p.skill === "tinkerer") {
|
||||
const discarded = p.cards.filter((c) => c.used > 0);
|
||||
s.discard.push(...discarded.map((c) => c.id));
|
||||
p.cards = p.cards.filter((c) => c.used === 0);
|
||||
}
|
||||
p.injuries.push(injury);
|
||||
p.pendingInjuries--;
|
||||
event(s, `${p.name} suffered ${injury === "amnesia" ? "amnesia" : `a ${injury} injury`}.`, "injury");
|
||||
afterMovement(s);
|
||||
break;
|
||||
}
|
||||
case "erupt":
|
||||
if (s.phase !== "eruption") throw Error("It is not time for an eruption.");
|
||||
erupt(s);
|
||||
if (!s.outcome) startRound(s);
|
||||
break;
|
||||
default:
|
||||
throw Error("Unknown action.");
|
||||
}
|
||||
}
|
||||
export function applyMove(data: State, input: unknown, seat: number): State {
|
||||
if (!Number.isInteger(seat) || seat < 0 || seat >= data.players.length) throw Error("Invalid player.");
|
||||
if (!input || typeof input !== "object" || Array.isArray(input)) throw Error("Invalid move.");
|
||||
const raw = input as Record<string, unknown>;
|
||||
if (typeof raw.action !== "string") throw Error("Invalid action.");
|
||||
const allowed = ["action", "keep", "drop", "path", "ids", "id", "target", "tiles", "face", "copy", "injury", "die"];
|
||||
const move = Object.fromEntries(allowed.filter((k) => Object.hasOwn(raw, k)).map((k) => [k, raw[k]])) as Move;
|
||||
if (JSON.stringify(move).length > 3000) throw Error("Move is too large.");
|
||||
const s = structuredClone(data);
|
||||
execute(s, move, seat);
|
||||
s.revision++;
|
||||
s.history.push({ player: seat, move });
|
||||
return s;
|
||||
}
|
||||
export function stripSecret(s: State, seat?: number): View {
|
||||
const { seed: _, counter: __, deck, history: ___, initOptions: ____, ...publicState } = structuredClone(s);
|
||||
const revealed = s.phase === "movement" || s.phase === "eruption" || s.phase === "ended";
|
||||
publicState.players.forEach((p, i) => {
|
||||
p.dice.forEach((d) => {
|
||||
if (!revealed && i !== seat && !p.radio && !d.aside) d.face = 0;
|
||||
});
|
||||
});
|
||||
publicState.ghost.forEach((d) => {
|
||||
if (!revealed && !s.ghostVisible.includes(d.id)) d.face = 0;
|
||||
});
|
||||
return { ...publicState, deckCount: deck.length };
|
||||
}
|
||||
export function activePlayers(s: State): number[] {
|
||||
if (s.outcome) return [];
|
||||
if (s.pending) return s.pending.players;
|
||||
const injured = s.players.flatMap((p, i) => (p.pendingInjuries ? [i] : []));
|
||||
if (injured.length) return injured;
|
||||
if (s.phase === "movement")
|
||||
return s.activeResolution === null
|
||||
? s.players.flatMap((p, i) => (p.resolved ? [] : [i]))
|
||||
: [
|
||||
s.activeResolution,
|
||||
...s.players.flatMap((p, i) =>
|
||||
i !== s.activeResolution && hasSkill(p, "gatherer") && p.powerBars > 0 ? [i] : []
|
||||
),
|
||||
];
|
||||
if (s.phase === "eruption") return [0];
|
||||
if (s.phase === "planning" || s.phase === "equipment") return s.players.map((_, i) => i);
|
||||
return s.players.flatMap((p, i) => ((s.phase === "setup" ? p.setupDone : p.ready) ? [] : [i]));
|
||||
}
|
||||
export function dropGamePlayer(s: State, seat: number): State {
|
||||
if (!s.players[seat]) throw Error("Invalid player.");
|
||||
const next = structuredClone(s);
|
||||
end(next, "lost", `${next.players[seat]!.name} left the expedition.`);
|
||||
next.revision++;
|
||||
next.history.push({ player: seat, move: { action: "$drop" } });
|
||||
return next;
|
||||
}
|
||||
export function setPlayerName(s: State, seat: number, name: string): State {
|
||||
if (!s.players[seat] || typeof name !== "string") throw Error("Invalid player metadata.");
|
||||
const next = structuredClone(s);
|
||||
next.players[seat]!.name = name;
|
||||
next.history.push({ player: seat, move: { action: "$name", name } });
|
||||
return next;
|
||||
}
|
||||
export function replay(s: State, to = s.history.length): State {
|
||||
let state = initGame(s.players.length, s.initOptions, s.seed);
|
||||
for (const e of s.history.slice(0, to)) {
|
||||
if (e.move.action === "$drop") state = dropGamePlayer(state, e.player);
|
||||
else if (e.move.action === "$name") state = setPlayerName(state, e.player, e.move.name as string);
|
||||
else state = applyMove(state, e.move, e.player);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
90
packages/engine/src/types.ts
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
import type { EquipmentId, Skill, Injury, Color } from "./data.js";
|
||||
export type Phase = "setup" | "planning" | "reroll" | "equipment" | "movement" | "eruption" | "ended";
|
||||
export interface Die {
|
||||
id: string;
|
||||
type: number;
|
||||
owner: number;
|
||||
face: number;
|
||||
aside: boolean;
|
||||
remove: boolean;
|
||||
}
|
||||
export interface Card {
|
||||
id: EquipmentId;
|
||||
used: number;
|
||||
availableRound: number;
|
||||
}
|
||||
export interface Player {
|
||||
name: string;
|
||||
character: number;
|
||||
skill: Skill;
|
||||
position: string;
|
||||
path: string[];
|
||||
dice: Die[];
|
||||
cards: Card[];
|
||||
stamina: number;
|
||||
injuries: Injury[];
|
||||
pendingInjuries: number;
|
||||
ready: boolean;
|
||||
rerolls: number;
|
||||
powerBars: number;
|
||||
radio: boolean;
|
||||
aid: boolean;
|
||||
bonus: number;
|
||||
resolved: boolean;
|
||||
setupDone: boolean;
|
||||
buddyUsed: boolean;
|
||||
}
|
||||
export interface Cell {
|
||||
id: string;
|
||||
x: number;
|
||||
y: number;
|
||||
terrain: number;
|
||||
lava: boolean;
|
||||
equipment: boolean;
|
||||
eruption: number;
|
||||
}
|
||||
export interface Event {
|
||||
round: number;
|
||||
text: string;
|
||||
type: "phase" | "move" | "equipment" | "eruption" | "injury" | "end";
|
||||
}
|
||||
export interface Pending {
|
||||
kind: "reroll" | "lend";
|
||||
players: number[];
|
||||
remaining: number;
|
||||
required: boolean;
|
||||
receiver?: number;
|
||||
}
|
||||
export interface State {
|
||||
schemaVersion: 1;
|
||||
seed: string;
|
||||
counter: number;
|
||||
round: number;
|
||||
phase: Phase;
|
||||
players: Player[];
|
||||
board: Cell[];
|
||||
deck: EquipmentId[];
|
||||
discard: EquipmentId[];
|
||||
difficulty: number;
|
||||
log: Event[];
|
||||
revision: number;
|
||||
outcome: null | "won" | "lost";
|
||||
reason: string;
|
||||
activeResolution: number | null;
|
||||
pending: Pending | null;
|
||||
ghost: Die[];
|
||||
ghostVisible: string[];
|
||||
history: { player: number; move: Record<string, unknown> }[];
|
||||
initOptions: Record<string, unknown>;
|
||||
}
|
||||
export interface View extends Omit<State, "seed" | "counter" | "deck" | "history" | "initOptions"> {
|
||||
deckCount: number;
|
||||
}
|
||||
export interface Move {
|
||||
action: string;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
export interface ResolvedFace {
|
||||
value: number;
|
||||
color: Color;
|
||||
}
|
||||
4
packages/engine/tsconfig.build.json
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"exclude": ["src/**/*.spec.ts"]
|
||||
}
|
||||
15
packages/engine/tsconfig.json
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"strict": true,
|
||||
"noUncheckedIndexedAccess": true,
|
||||
"declaration": true,
|
||||
"outDir": "dist",
|
||||
"rootDir": ".",
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"include": ["src/**/*.ts", "index.ts", "wrapper.ts"]
|
||||
}
|
||||
37
packages/engine/wrapper.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import {
|
||||
initGame,
|
||||
applyMove,
|
||||
stripSecret,
|
||||
activePlayers,
|
||||
dropGamePlayer,
|
||||
setPlayerName,
|
||||
replay as replayGame,
|
||||
} from "./src/game.js";
|
||||
import type { State } from "./src/types.js";
|
||||
export { stripSecret };
|
||||
export const hashSeed = true;
|
||||
export async function init(players: number, expansions: string[], options: Record<string, unknown>, seed: string) {
|
||||
if (expansions.length) throw Error("No expansions are implemented.");
|
||||
return initGame(players, options, seed);
|
||||
}
|
||||
export function move(data: State, input: unknown, player: number) {
|
||||
return applyMove(data, input, player);
|
||||
}
|
||||
export const ended = (s: State) => s.outcome !== null;
|
||||
export const currentPlayer = (s: State) => {
|
||||
const seats = activePlayers(s);
|
||||
return seats.length === 1 ? seats[0] : seats.length ? seats : undefined;
|
||||
};
|
||||
export const round = (s: State) => s.round;
|
||||
export const scores = (s: State) =>
|
||||
s.players.map((p) => (s.outcome === "won" ? 4 - p.injuries.length + p.cards.length : 0));
|
||||
export const rankings = (s: State) => s.players.map(() => 1);
|
||||
export const logLength = (s: State) => s.log.length;
|
||||
export const logSlice = (s: State, o: { player?: number; start: number; end?: number }) => ({
|
||||
log: s.log.slice(o.start, o.end).map((e) => ({ ...e, simple: e.text })),
|
||||
});
|
||||
export const replay = (s: State, o?: { to?: number }) => replayGame(s, o?.to);
|
||||
export function setPlayerMetaData(s: State, seat: number, meta: { name: string }) {
|
||||
return setPlayerName(s, seat, meta.name);
|
||||
}
|
||||
export const dropPlayer = dropGamePlayer;
|
||||
13
packages/viewer/index.html
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="theme-color" content="#132d28" />
|
||||
<title>Fuji — Escape together</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/dev.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
23
packages/viewer/package.json
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"name": "fuji-viewer",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"license": "AGPL-3.0-only",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite --host 127.0.0.1 --port 5187 --strictPort",
|
||||
"build": "vite build",
|
||||
"check": "svelte-check --tsconfig ./tsconfig.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"fuji-engine": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sveltejs/vite-plugin-svelte": "7.2.0",
|
||||
"@types/node": "24.10.1",
|
||||
"svelte": "5.56.8",
|
||||
"svelte-check": "4.7.4",
|
||||
"typescript": "5.9.3",
|
||||
"vite": "8.2.0"
|
||||
}
|
||||
}
|
||||
762
packages/viewer/src/App.svelte
Normal file
|
|
@ -0,0 +1,762 @@
|
|||
<script lang="ts">
|
||||
import {
|
||||
terrain,
|
||||
cell,
|
||||
paths,
|
||||
rerollAllowance,
|
||||
requirementLabel,
|
||||
matches,
|
||||
face,
|
||||
total,
|
||||
comparison,
|
||||
threatened,
|
||||
walkable,
|
||||
distance,
|
||||
SKILLS,
|
||||
EQUIPMENT,
|
||||
INJURIES,
|
||||
EXHAUSTION,
|
||||
CHARACTER_COLORS,
|
||||
hasSkill,
|
||||
activeDice,
|
||||
type EquipmentId,
|
||||
type View,
|
||||
} from "fuji-engine";
|
||||
import type { Store } from "./lib/store.svelte";
|
||||
import { art } from "./lib/assets";
|
||||
import Landscape from "./lib/Landscape.svelte";
|
||||
import Die from "./lib/Die.svelte";
|
||||
let { store }: { store: Store } = $props();
|
||||
const s = $derived(store.state);
|
||||
const seat = $derived(store.seat);
|
||||
const me = $derived(seat === undefined ? undefined : s?.players[seat]);
|
||||
let inspected = $state("");
|
||||
let draft = $state<string[]>([]);
|
||||
let dice = $state<string[]>([]);
|
||||
let tilePicks = $state<string[]>([]);
|
||||
let tool = $state<EquipmentId | null>(null);
|
||||
let copied = $state<EquipmentId>("torch");
|
||||
let target = $state(0);
|
||||
let turnFace = $state(1);
|
||||
let keep = $state<string[]>([]);
|
||||
let drop = $state("");
|
||||
let trace = $state(false);
|
||||
let help = $state(false);
|
||||
let newGame = $state(false);
|
||||
let newPlayers = $state(3);
|
||||
let newDifficulty = $state(1);
|
||||
let newSeed = $state("first-light");
|
||||
const reachable = $derived(s && seat !== undefined ? paths(s, seat) : {});
|
||||
const focusId = $derived(inspected || me?.path.at(-1) || s?.board.find((c) => c.terrain > 3)?.id || "");
|
||||
const focus = $derived(s && focusId ? cell(s, focusId) : undefined);
|
||||
const focusTerrain = $derived(focus ? terrain(focus.terrain) : undefined);
|
||||
const currentRoute = $derived(draft.length ? draft : (me?.path ?? []));
|
||||
const destination = $derived(s && currentRoute.length ? terrain(cell(s, currentRoute.at(-1)!).terrain) : undefined);
|
||||
const actionTool = $derived(tool === "knife" ? copied : tool);
|
||||
const pendingMe = $derived(s?.pending && seat !== undefined && s.pending.players.includes(seat));
|
||||
const revealed = $derived(s?.phase === "movement" || s?.phase === "eruption" || s?.phase === "ended");
|
||||
const result = $derived(s && seat !== undefined && revealed ? comparison(s, seat) : null);
|
||||
const rule = $derived(focusTerrain?.requirement);
|
||||
const localTotal = $derived(me && focusTerrain ? total(me, focusTerrain.id) : 0);
|
||||
const danger = $derived(s ? threatened(s) : []);
|
||||
const nextAction = $derived(
|
||||
!s
|
||||
? ""
|
||||
: {
|
||||
setup: "Prepare your expedition",
|
||||
planning: "Find your way forward",
|
||||
reroll: "A moment of silence",
|
||||
equipment: "Make the most of your gear",
|
||||
movement: "Every step counts",
|
||||
eruption: "The mountain is waking",
|
||||
ended: s.outcome === "won" ? "Together, you made it." : "The mountain won.",
|
||||
}[s.phase]
|
||||
);
|
||||
$effect(() => {
|
||||
const revision = s?.revision;
|
||||
const currentSeat = seat;
|
||||
void revision;
|
||||
void currentSeat;
|
||||
dice = [];
|
||||
draft = [];
|
||||
tilePicks = [];
|
||||
tool = null;
|
||||
trace = false;
|
||||
if (me) {
|
||||
keep = me.cards.slice(0, SKILLS[me.skill].keep).map((c) => c.id);
|
||||
drop = me.dice.at(-1)?.id ?? "";
|
||||
target = seat ?? 0;
|
||||
}
|
||||
});
|
||||
function pickDie(id: string) {
|
||||
dice = dice.includes(id) ? dice.filter((x) => x !== id) : [...dice, id];
|
||||
}
|
||||
function chooseLocation(id: string) {
|
||||
inspected = id;
|
||||
if (tool && ["binoculars", "rope"].includes(actionTool ?? "")) {
|
||||
tilePicks = tilePicks.includes(id)
|
||||
? tilePicks.filter((x) => x !== id)
|
||||
: [...tilePicks, id].slice(actionTool === "rope" ? -1 : -2);
|
||||
return;
|
||||
}
|
||||
if (s?.phase !== "planning" || !me || me.ready) return;
|
||||
if (trace && draft.length) {
|
||||
const last = draft.at(-1)!;
|
||||
if (draft.includes(id)) {
|
||||
draft = draft.slice(0, draft.indexOf(id) + 1);
|
||||
} else if (
|
||||
walkable(cell(s, id)) &&
|
||||
distance(cell(s, last), cell(s, id)) === 1 &&
|
||||
draft.length < (hasSkill(me, "scout") ? 5 : 4)
|
||||
) {
|
||||
draft = [...draft, id];
|
||||
}
|
||||
} else if (reachable[id]) draft = reachable[id]!;
|
||||
}
|
||||
function mobileAction() {
|
||||
if (!s || !me) return;
|
||||
if (s.pending || me.pendingInjuries || s.phase === "setup") {
|
||||
document.querySelector(".journey")?.scrollIntoView({ behavior: "smooth" });
|
||||
return;
|
||||
}
|
||||
if (s.phase === "planning") {
|
||||
store.dispatch(
|
||||
draft.length
|
||||
? { action: "plan", path: draft }
|
||||
: { action: me.ready ? "plan" : "ready", ...(me.ready ? { path: me.path } : {}) }
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (s.phase === "reroll") {
|
||||
store.dispatch(me.rerolls && dice.length ? { action: "reroll", ids: dice } : { action: "finishRerolls" });
|
||||
return;
|
||||
}
|
||||
if (s.phase === "equipment") {
|
||||
document.querySelector(".journey")?.scrollIntoView({ behavior: "smooth" });
|
||||
return;
|
||||
}
|
||||
if (s.phase === "movement") {
|
||||
if (s.activeResolution === null && !me.resolved) store.dispatch({ action: "beginMovement" });
|
||||
else if (s.activeResolution === seat) store.dispatch({ action: "resolve" });
|
||||
else document.querySelector(".journey")?.scrollIntoView({ behavior: "smooth" });
|
||||
return;
|
||||
}
|
||||
if (s.phase === "eruption" && seat === 0) store.dispatch({ action: "erupt" });
|
||||
}
|
||||
const mobileLabel = $derived(
|
||||
!s || !me
|
||||
? ""
|
||||
: s.pending || me.pendingInjuries
|
||||
? "Resolve effect"
|
||||
: s.phase === "setup"
|
||||
? "Prepare expedition"
|
||||
: s.phase === "planning"
|
||||
? draft.length
|
||||
? "Set route"
|
||||
: me.ready
|
||||
? "Change route"
|
||||
: "Ready to travel"
|
||||
: s.phase === "reroll"
|
||||
? me.rerolls && dice.length
|
||||
? "Reroll selected"
|
||||
: "Keep dice"
|
||||
: s.phase === "equipment"
|
||||
? "Equipment & reveal"
|
||||
: s.phase === "movement"
|
||||
? "Resolve journey"
|
||||
: "Advance lava"
|
||||
);
|
||||
function confirmTool() {
|
||||
if (!tool) return;
|
||||
store.dispatch({
|
||||
action: "equipment",
|
||||
id: tool,
|
||||
copy: copied,
|
||||
ids: dice,
|
||||
tiles: tilePicks,
|
||||
target,
|
||||
face: turnFace,
|
||||
});
|
||||
}
|
||||
function chooseTool(id: EquipmentId) {
|
||||
tool = tool === id ? null : id;
|
||||
tilePicks = [];
|
||||
dice = [];
|
||||
}
|
||||
function modalFocus(node: HTMLElement) {
|
||||
const previous = document.activeElement as HTMLElement | null;
|
||||
queueMicrotask(() => node.querySelector<HTMLElement>("button")?.focus());
|
||||
function key(e: KeyboardEvent) {
|
||||
if (e.key === "Escape") {
|
||||
help = false;
|
||||
newGame = false;
|
||||
}
|
||||
if (e.key === "Tab") {
|
||||
const all = [...node.querySelectorAll<HTMLElement>('button:not(:disabled),input,select,[tabindex="0"]')];
|
||||
const first = all[0],
|
||||
last = all.at(-1);
|
||||
if (e.shiftKey && document.activeElement === first) {
|
||||
e.preventDefault();
|
||||
last?.focus();
|
||||
} else if (!e.shiftKey && document.activeElement === last) {
|
||||
e.preventDefault();
|
||||
first?.focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
node.addEventListener("keydown", key);
|
||||
return {
|
||||
destroy() {
|
||||
node.removeEventListener("keydown", key);
|
||||
previous?.focus();
|
||||
},
|
||||
};
|
||||
}
|
||||
const phaseNumber = $derived(
|
||||
!s ? 0 : ["setup", "planning", "reroll", "equipment", "movement", "eruption", "ended"].indexOf(s.phase)
|
||||
);
|
||||
</script>
|
||||
|
||||
{#if s}
|
||||
<main class="expedition">
|
||||
<header class="masthead">
|
||||
<div class="identity">
|
||||
<span class="mountain-mark" aria-hidden="true">△</span>
|
||||
<h1>FUJI<span>by Wolfgang Warsch</span></h1>
|
||||
</div>
|
||||
<div class="round-status">
|
||||
<span class="live-dot"></span><span
|
||||
>{s.phase === "setup" ? "THE EXPEDITION" : `ROUND ${String(s.round).padStart(2, "0")}`}</span
|
||||
><span class="separator">/</span><span
|
||||
>{s.outcome
|
||||
? "Journey complete"
|
||||
: s.phase === "reroll"
|
||||
? "Quiet phase"
|
||||
: s.phase === "setup"
|
||||
? "Preparation"
|
||||
: s.phase}</span
|
||||
>
|
||||
</div>
|
||||
<button class="text-button help-button" onclick={() => (help = true)} aria-label="Open playing guide"
|
||||
>How to play <span>?</span></button
|
||||
>
|
||||
</header>
|
||||
<section class="team" aria-label="Your expedition">
|
||||
{#each s.players as p, i}
|
||||
<button
|
||||
class="teammate"
|
||||
class:own={seat === i}
|
||||
style:--player-color={CHARACTER_COLORS[p.character]}
|
||||
onclick={() => {
|
||||
if (store.local) store.selectSeat(i);
|
||||
}}
|
||||
disabled={!store.local}
|
||||
aria-label={`${p.name}${seat === i ? ", you" : ""}. ${EXHAUSTION - p.stamina} stamina remaining${store.local ? ". Switch to this player." : ""}`}
|
||||
>
|
||||
<img src={art("character", p.character + 1)} alt="" class="portrait" />
|
||||
<div class="teammate-info">
|
||||
<span class="teammate-name"
|
||||
>{p.name}{#if seat === i}<small>YOU</small>{/if}</span
|
||||
><span class="role-name">{SKILLS[p.skill].name}</span><span class="stamina-track" aria-hidden="true"
|
||||
><i style:width={`${(1 - p.stamina / EXHAUSTION) * 100}%`}></i></span
|
||||
>
|
||||
</div>
|
||||
<div class="teammate-status">
|
||||
<span>{EXHAUSTION - p.stamina}<small> / {EXHAUSTION}</small></span><span class="ready-label"
|
||||
>{p.pendingInjuries
|
||||
? "Injured"
|
||||
: p.ready || (p.setupDone && s.phase === "setup")
|
||||
? "Ready ✓"
|
||||
: p.resolved && s.phase === "movement"
|
||||
? "Moved"
|
||||
: s.phase === "setup"
|
||||
? "Packing"
|
||||
: p.injuries.length
|
||||
? `${p.injuries.length} injury`
|
||||
: "Stamina"}</span
|
||||
>
|
||||
</div>
|
||||
</button>
|
||||
{/each}
|
||||
</section>
|
||||
<div class="game-layout">
|
||||
<div class="world-column">
|
||||
<Landscape
|
||||
state={s}
|
||||
{seat}
|
||||
route={currentRoute}
|
||||
selected={tool ? (tilePicks.at(-1) ?? focusId) : (currentRoute.at(-1) ?? focusId)}
|
||||
reachable={s.phase === "planning" && !me?.ready ? Object.keys(reachable) : []}
|
||||
onclick={chooseLocation}
|
||||
oninspect={(id) => (inspected = id)}
|
||||
/>
|
||||
<section class="personal" aria-label="Your dice">
|
||||
<div class="personal-title">
|
||||
<div>
|
||||
<span class="eyebrow"
|
||||
>{seat === undefined ? "SPECTATOR VIEW" : revealed ? "DICE REVEALED" : "BEHIND YOUR SCREEN"}</span
|
||||
>
|
||||
<h2>{me ? SKILLS[me.skill].name : "The expedition"}</h2>
|
||||
</div>
|
||||
<span class="privacy-tag"
|
||||
>{revealed ? "Visible to everyone" : me?.radio ? "Wireless is active" : "Only you can see these"}</span
|
||||
>
|
||||
</div>
|
||||
{#if me}
|
||||
<div class="dice-row">
|
||||
{#each me.dice as d (d.id)}<Die
|
||||
die={d}
|
||||
selected={dice.includes(d.id)}
|
||||
relevant={!!rule && matches(face(d), rule)}
|
||||
disabled={(d.aside && !me.pendingInjuries) || store.waiting || s.phase === "setup"}
|
||||
onclick={() => pickDie(d.id)}
|
||||
/>{/each}
|
||||
{#if focusTerrain && s.phase !== "setup"}<div class="dice-total">
|
||||
<strong>{localTotal}</strong><span>your total<br />for this location</span>
|
||||
</div>{/if}
|
||||
</div>
|
||||
<div class="skill-line">
|
||||
<span class="skill-symbol">◇</span><span
|
||||
>{me.injuries.includes("amnesia")
|
||||
? "Your skill is unavailable due to amnesia."
|
||||
: SKILLS[me.skill].description}</span
|
||||
>{#if me.powerBars}<span class="power-bars">{me.powerBars} power bar{me.powerBars === 1 ? "" : "s"}</span
|
||||
>{/if}
|
||||
</div>
|
||||
{#if me.injuries.length}<div class="injury-list">
|
||||
{#each me.injuries as injury}<span>{injury}</span>{/each}
|
||||
</div>{/if}
|
||||
{/if}
|
||||
</section>
|
||||
</div>
|
||||
<aside class="journey">
|
||||
<div class="phase-heading">
|
||||
<span class="eyebrow"
|
||||
>{s.outcome
|
||||
? "EXPEDITION RESULT"
|
||||
: s.phase === "setup"
|
||||
? "BEFORE YOU BEGIN"
|
||||
: `PHASE ${phaseNumber + 1} OF 6`}</span
|
||||
>
|
||||
<h2>{nextAction}</h2>
|
||||
</div>
|
||||
<nav class="phase-track" aria-label="Round phases">
|
||||
{#each ["Plan", "Reroll", "Equip", "Move", "Erupt"] as label, i}<span
|
||||
class:active={phaseNumber === i + 1}
|
||||
class:complete={phaseNumber > i + 1}>{label}</span
|
||||
>{/each}
|
||||
</nav>
|
||||
{#if store.error}<div class="error" role="alert">
|
||||
{store.error}<button
|
||||
class="text-button"
|
||||
onclick={() => {
|
||||
store.waiting = false;
|
||||
store.error = "";
|
||||
}}>Dismiss</button
|
||||
>
|
||||
</div>{/if}
|
||||
{#if s.outcome}
|
||||
<div class="outcome" class:won={s.outcome === "won"}>
|
||||
<span class="outcome-icon">{s.outcome === "won" ? "✧" : "△"}</span>
|
||||
<p>{s.reason}</p>
|
||||
<p class="muted">{s.round} rounds · {s.players.length} adventurers</p>
|
||||
{#if s.outcome === "won"}<strong
|
||||
>{s.players.reduce((n, p) => n + 4 - p.injuries.length + p.cards.length, 0)} expedition points</strong
|
||||
>{/if}
|
||||
</div>
|
||||
{#if store.local}<button class="primary" onclick={() => (newGame = true)}>Start a new expedition</button>{/if}
|
||||
{:else if !me}<p class="instruction">Follow the expedition. Private dice remain hidden until the reveal.</p>
|
||||
{:else if s.phase === "setup"}
|
||||
{#if me.setupDone}<p class="instruction">
|
||||
Your bag is packed. Waiting for the rest of the expedition.
|
||||
</p>{:else}
|
||||
<p class="instruction">
|
||||
Keep {SKILLS[me.skill].keep} equipment card{SKILLS[me.skill].keep > 1 ? "s" : ""} for the journey.
|
||||
</p>
|
||||
<div class="pack-options">
|
||||
{#each me.cards as c}<button
|
||||
class:selected={keep.includes(c.id)}
|
||||
onclick={() => (keep = keep.includes(c.id) ? keep.filter((id) => id !== c.id) : [...keep, c.id])}
|
||||
><img
|
||||
src={art("equipment", EQUIPMENT.findIndex((x) => x.id === c.id) + 1)}
|
||||
alt={EQUIPMENT.find((x) => x.id === c.id)?.name}
|
||||
/><span>{EQUIPMENT.find((x) => x.id === c.id)?.name}</span><i>{keep.includes(c.id) ? "✓" : "+"}</i
|
||||
></button
|
||||
>{/each}
|
||||
</div>
|
||||
{#if SKILLS[me.skill].dice === 5}<label class="field"
|
||||
>Choose the die to leave behind<select bind:value={drop}
|
||||
>{#each me.dice as d}<option value={d.id}>Type {"ABC"[d.type]} · die {d.id.split("-")[1]}</option
|
||||
>{/each}</select
|
||||
></label
|
||||
>{/if}
|
||||
<button
|
||||
class="primary"
|
||||
disabled={keep.length !== SKILLS[me.skill].keep || store.waiting}
|
||||
onclick={() => store.dispatch({ action: "setup", keep, drop })}
|
||||
>Ready for the journey <span>→</span></button
|
||||
>
|
||||
{/if}
|
||||
{:else if me.pendingInjuries}
|
||||
<p class="instruction">Choose an injury. Its effect lasts for the rest of the expedition.</p>
|
||||
<div class="injury-options">
|
||||
{#each INJURIES.filter((i) => !me.injuries.includes(i)) as injury}<button
|
||||
onclick={() => store.dispatch({ action: "injury", injury, die: dice[0] })}
|
||||
disabled={injury === "leg" && dice.length !== 1}
|
||||
><strong
|
||||
>{injury === "amnesia" ? "Amnesia" : `${injury[0]!.toUpperCase()}${injury.slice(1)} injury`}</strong
|
||||
><span
|
||||
>{{
|
||||
leg: "Select one of your dice to lose after this round.",
|
||||
arm: "You can no longer use equipment.",
|
||||
eye: "Lose normal rerolls. Skill and equipment rerolls still work.",
|
||||
amnesia: "Lose your character skill.",
|
||||
}[injury]}</span
|
||||
></button
|
||||
>{/each}
|
||||
</div>
|
||||
{:else if s.pending}
|
||||
{#if pendingMe}<p class="instruction">
|
||||
{s.pending.kind === "lend"
|
||||
? "A teammate asks to borrow a die. Select one to lend, or decline."
|
||||
: s.pending.required
|
||||
? "Choose exactly one die to reroll."
|
||||
: "Select any dice to reroll. You may also stop."}
|
||||
</p>
|
||||
<button
|
||||
class="primary"
|
||||
disabled={store.waiting ||
|
||||
(s.pending.required && dice.length !== 1) ||
|
||||
(s.pending.kind === "lend" && dice.length !== 1)}
|
||||
onclick={() => store.dispatch({ action: "respond", ids: dice })}
|
||||
>{s.pending.kind === "lend" ? "Lend selected die" : "Reroll selected dice"}</button
|
||||
>{#if !s.pending.required}<button class="secondary" onclick={() => store.dispatch({ action: "decline" })}
|
||||
>{s.pending.kind === "lend" ? "Decline" : "Finish rerolls"}</button
|
||||
>{/if}
|
||||
{:else}<p class="instruction">
|
||||
Waiting for {s.pending.players.map((i) => s.players[i]!.name).join(", ")} to resolve an equipment effect.
|
||||
</p>{/if}
|
||||
{:else if s.phase === "planning"}
|
||||
<p class="instruction">
|
||||
Choose a destination. Share your intentions, but keep numbers and exact dice results private.
|
||||
</p>
|
||||
{#if destination}<div class="destination">
|
||||
<img src={art("land", destination.id)} alt="" />
|
||||
<div>
|
||||
<span class="eyebrow">YOUR DESTINATION</span>
|
||||
<h3>{destination.name}</h3>
|
||||
<span>{requirementLabel(destination.requirement)}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="journey-stats">
|
||||
<div><strong>{currentRoute.length - 1}</strong><span>spaces</span></div>
|
||||
<div><strong>{rerollAllowance(s, seat!, currentRoute)}</strong><span>rerolls</span></div>
|
||||
<div><strong>{total(me, destination.id)}</strong><span>your total</span></div>
|
||||
</div>{/if}
|
||||
{#if currentRoute.some((id) => cell(s, id).eruption)}<p class="warning">
|
||||
This route crosses an eruption marker. Moving here triggers extra lava.
|
||||
</p>{/if}
|
||||
{#if danger.includes(currentRoute.at(-1) ?? "")}<p class="warning">
|
||||
This destination is threatened by the next eruption.
|
||||
</p>{/if}
|
||||
{#if draft.length}<button
|
||||
class="primary"
|
||||
disabled={store.waiting}
|
||||
onclick={() => store.dispatch({ action: "plan", path: draft })}>Set this route <span>→</span></button
|
||||
>{:else if !me.ready}<button
|
||||
class="primary"
|
||||
disabled={store.waiting}
|
||||
onclick={() => store.dispatch({ action: "ready" })}>Ready to travel <span>→</span></button
|
||||
>{:else}<p class="confirmed">✓ Your route is set. Waiting for the team.</p>
|
||||
<button class="text-button" onclick={() => store.dispatch({ action: "plan", path: me.path })}
|
||||
>Change my route</button
|
||||
>{/if}
|
||||
<button
|
||||
class="text-button trace-button"
|
||||
onclick={() => {
|
||||
trace = !trace;
|
||||
if (trace) draft = [me.position];
|
||||
}}>{trace ? "Stop tracing" : "Trace a specific path"}</button
|
||||
>{#if trace}<p class="muted small">
|
||||
Click adjacent locations to build your route. Click an earlier step to go back.
|
||||
</p>{/if}
|
||||
{:else if s.phase === "reroll"}
|
||||
<p class="instruction">
|
||||
No discussion during this phase. Select the dice you want to reroll, or keep your result.
|
||||
</p>
|
||||
<div class="reroll-count">
|
||||
<strong>{me.rerolls}</strong><span>reroll{me.rerolls === 1 ? "" : "s"} remaining</span>
|
||||
</div>
|
||||
{#if !me.ready}<button
|
||||
class="primary"
|
||||
disabled={!me.rerolls || !dice.length || store.waiting}
|
||||
onclick={() => store.dispatch({ action: "reroll", ids: dice })}
|
||||
>Reroll {dice.length || "selected"} dice <span>↻</span></button
|
||||
><button
|
||||
class="secondary"
|
||||
onclick={() => store.dispatch({ action: "finishRerolls" })}
|
||||
disabled={store.waiting}
|
||||
>Keep my dice{hasSkill(me, "gatherer") && me.rerolls
|
||||
? ` · gain ${Math.min(me.rerolls, 3 - me.powerBars)} bars`
|
||||
: ""}</button
|
||||
>
|
||||
{#if hasSkill(me, "buddy") && !me.buddyUsed}<button
|
||||
class="text-button"
|
||||
disabled={dice.length !== 1}
|
||||
onclick={() => store.dispatch({ action: "buddy", ids: dice })}>Set one selected die aside</button
|
||||
>{/if}
|
||||
{:else}<p class="confirmed">✓ Your dice are kept. Waiting for the team.</p>{/if}
|
||||
{:else if s.phase === "equipment"}
|
||||
<p class="instruction">
|
||||
Discuss equipment with your teammates. Your dice are still private and your destination is locked.
|
||||
</p>
|
||||
{#if !me.ready}<button
|
||||
class="primary"
|
||||
onclick={() => store.dispatch({ action: "ready" })}
|
||||
disabled={store.waiting}>Ready to reveal <span>→</span></button
|
||||
>{:else}<p class="confirmed">✓ Ready. Waiting for the team.</p>{/if}
|
||||
{:else if s.phase === "movement"}
|
||||
{#if s.activeResolution === null}<p class="instruction">
|
||||
Choose who moves next. A route that triggers extra lava is often best resolved last.
|
||||
</p>
|
||||
{#if !me.resolved}<button class="primary" onclick={() => store.dispatch({ action: "beginMovement" })}
|
||||
>Resolve my journey <span>→</span></button
|
||||
>{:else}<p class="confirmed">✓ Your journey is resolved.</p>{/if}
|
||||
{:else if s.activeResolution === seat && result}<div class="comparison">
|
||||
<span class="eyebrow">{result.success ? "YOU CAN MOVE" : "YOU MUST STAY"}</span><strong
|
||||
>{result.own}<small> vs </small>{Math.max(...result.peers.map((p) => p.total))}</strong
|
||||
>
|
||||
<p>
|
||||
{result.success
|
||||
? `Lead of ${result.margin} · lose ${result.loss} stamina`
|
||||
: `Tie or lower · lose ${result.loss} stamina`}
|
||||
</p>
|
||||
{#each result.peers as peer}<div>
|
||||
<span>{peer.seat === -1 ? "Neutral dice" : s.players[peer.seat]!.name}</span><span>{peer.total}</span>
|
||||
</div>{/each}
|
||||
</div>
|
||||
<button class="primary" onclick={() => store.dispatch({ action: "resolve" })}
|
||||
>Continue journey <span>→</span></button
|
||||
>
|
||||
{:else}<p class="instruction">{s.players[s.activeResolution]!.name} is resolving their journey.</p>{/if}
|
||||
{#if s.activeResolution !== null && hasSkill(me, "gatherer") && me.powerBars}<button
|
||||
class="secondary"
|
||||
onclick={() => store.dispatch({ action: "bar" })}
|
||||
>Spend a power bar · +1 for {s.players[s.activeResolution]!.name}</button
|
||||
>{/if}
|
||||
{:else if s.phase === "eruption"}
|
||||
<p class="instruction">Everyone has moved. The lava will spread one step to every adjacent location.</p>
|
||||
<div class="eruption-count"><strong>{danger.length}</strong><span>locations threatened</span></div>
|
||||
<button class="primary ember" disabled={seat !== 0} onclick={() => store.dispatch({ action: "erupt" })}
|
||||
>{seat === 0 ? "Let the lava advance" : "Waiting for the expedition leader"} <span>→</span></button
|
||||
>
|
||||
{/if}
|
||||
{#if me && s.phase !== "setup" && !s.outcome}
|
||||
<section class="equipment-section">
|
||||
<div class="section-title">
|
||||
<h3>Your equipment</h3>
|
||||
<span>{me.cards.length}</span>
|
||||
</div>
|
||||
{#if !me.cards.length}<p class="muted small">Find equipment along the trail.</p>{/if}
|
||||
<div class="equipment-list">
|
||||
{#each me.cards as c}{@const info = EQUIPMENT.find((e) => e.id === c.id)!}{@const available =
|
||||
c.availableRound <= s.round &&
|
||||
!me.injuries.includes("arm") &&
|
||||
(info.phases as readonly number[]).includes(
|
||||
s.phase === "planning" ? 2 : s.phase === "equipment" ? 4 : -1
|
||||
) &&
|
||||
!s.pending}
|
||||
<button
|
||||
class:usable={available}
|
||||
class:open={tool === c.id}
|
||||
onclick={() => chooseTool(c.id)}
|
||||
aria-expanded={tool === c.id}
|
||||
><img src={art("equipment", EQUIPMENT.indexOf(info) + 1)} alt="" /><span
|
||||
><strong>{info.name}</strong><small
|
||||
>{c.availableRound > s.round
|
||||
? "Available next round"
|
||||
: c.used
|
||||
? "One use left"
|
||||
: available
|
||||
? "Available now"
|
||||
: `Phase ${info.phases.join(" / ")}`}</small
|
||||
></span
|
||||
><span class="equipment-plus">{tool === c.id ? "−" : "+"}</span></button
|
||||
>
|
||||
{/each}
|
||||
</div>
|
||||
{#if tool}{@const c = me.cards.find((c) => c.id === tool)!}{@const info = EQUIPMENT.find(
|
||||
(e) => e.id === tool
|
||||
)!}
|
||||
<div class="tool-form">
|
||||
<p>{info.description}</p>
|
||||
{#if tool === "knife"}<label class="field"
|
||||
>Copy equipment<select bind:value={copied}
|
||||
>{#each s.players.flatMap( (p, i) => (i === seat ? [] : p.cards.filter((c) => c.id !== "knife" && c.availableRound <= s.round)) ) as c}<option
|
||||
value={c.id}>{EQUIPMENT.find((e) => e.id === c.id)?.name}</option
|
||||
>{/each}</select
|
||||
></label
|
||||
>{/if}
|
||||
{#if ["water", "lighter", "map"].includes(actionTool ?? "")}<label class="field"
|
||||
>Recipient<select bind:value={target}
|
||||
>{#each s.players as p, i}<option value={i}>{p.name}{i === seat ? " (you)" : ""}</option
|
||||
>{/each}</select
|
||||
></label
|
||||
>{/if}
|
||||
{#if ["shovel", "torch", "tape", "machete", "compass", "map"].includes(actionTool ?? "")}<p
|
||||
class="muted small"
|
||||
>
|
||||
Select the dice below the map. {dice.length} selected.
|
||||
</p>{/if}
|
||||
{#if actionTool === "shovel"}<label class="field"
|
||||
>New value<select bind:value={turnFace}
|
||||
>{#each [1, 2, 3, 4, 5, 6] as n}<option value={n}>{n}</option>{/each}</select
|
||||
></label
|
||||
>{/if}
|
||||
{#if ["binoculars", "rope"].includes(actionTool ?? "")}<p class="muted small">
|
||||
Choose {actionTool === "rope" ? "one adjacent location" : "two empty land locations"} on the map. {tilePicks.length}
|
||||
selected.
|
||||
</p>{/if}
|
||||
<button
|
||||
class="secondary"
|
||||
disabled={store.waiting ||
|
||||
c.availableRound > s.round ||
|
||||
me.injuries.includes("arm") ||
|
||||
!["planning", "equipment"].includes(s.phase)}
|
||||
onclick={confirmTool}>Use {info.name}</button
|
||||
>
|
||||
{#if hasSkill(me, "manager")}<label class="field"
|
||||
>Give to<select bind:value={target}
|
||||
>{#each s.players as p, i}{#if i !== seat}<option value={i}>{p.name}</option>{/if}{/each}</select
|
||||
></label
|
||||
><button class="text-button" onclick={() => store.dispatch({ action: "give", id: tool, target })}
|
||||
>Give equipment</button
|
||||
>{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</section>
|
||||
{/if}
|
||||
{#if focusTerrain && s.phase !== "setup"}<div class="location-detail">
|
||||
<span class="eyebrow">INSPECTING THE TRAIL</span><strong>{focusTerrain.name}</strong><span
|
||||
>{requirementLabel(focusTerrain.requirement)}{focusTerrain.reroll ? " · +1 reroll" : ""}</span
|
||||
>
|
||||
</div>{/if}
|
||||
</aside>
|
||||
</div>
|
||||
{#if revealed || s.players.some((p, i) => i !== seat && p.dice.some((d) => d.face > 0))}<section
|
||||
class="revealed-team"
|
||||
aria-label="Revealed dice"
|
||||
>
|
||||
{#each s.players as p, i}{#if i !== seat && (revealed || p.dice.some((d) => d.face > 0))}<div>
|
||||
<span class="eyebrow">{p.name}</span>
|
||||
<div class="mini-dice">
|
||||
{#each p.dice as d}<Die die={d} disabled relevant={!!rule && matches(face(d), rule)} />{/each}
|
||||
</div>
|
||||
</div>{/if}{/each}
|
||||
</section>{/if}
|
||||
{#if s.ghost.length}<details class="neutral-dice">
|
||||
<summary>Neutral dice · two-player variant A</summary>
|
||||
<div class="mini-dice">
|
||||
{#each s.ghost as d}<Die die={d} disabled />{/each}
|
||||
</div>
|
||||
</details>{/if}
|
||||
<footer class="journal">
|
||||
<div class="section-title">
|
||||
<h3>Expedition journal</h3>
|
||||
<span>ROUND {s.round}</span>
|
||||
</div>
|
||||
<ol>
|
||||
{#each s.log.slice(-5).reverse() as e, i}<li class:latest={i === 0}>
|
||||
<span class="journal-round">{String(e.round).padStart(2, "0")}</span><span>{e.text}</span>
|
||||
</li>{/each}
|
||||
</ol>
|
||||
</footer>
|
||||
<div class="credits">FUJI · Wolfgang Warsch <span>Illustrations by Weberson Santiago · Feuerland Spiele</span></div>
|
||||
{#if store.local}<div class="dev-toolbar">
|
||||
<span>Local playtest</span><span class="dev-hint">Click a player above to switch seats.</span><button
|
||||
onclick={() => store.teammateStep()}
|
||||
disabled={!!s.outcome}>Play next teammate action</button
|
||||
><button onclick={() => (newGame = true)}>New game</button>
|
||||
</div>{/if}
|
||||
{#if me && !s.outcome}<div class="mobile-dock">
|
||||
<div>
|
||||
<span class="eyebrow">{s.phase}</span><strong
|
||||
>{s.phase === "planning"
|
||||
? `${destination?.name ?? ""} · ${destination ? total(me, destination.id) : 0}`
|
||||
: s.phase === "reroll"
|
||||
? `${me.rerolls} rerolls remaining`
|
||||
: me.name}</strong
|
||||
>
|
||||
</div>
|
||||
<button
|
||||
onclick={mobileAction}
|
||||
disabled={store.waiting || (s.phase === "reroll" && me.ready) || (s.phase === "eruption" && seat !== 0)}
|
||||
>{mobileLabel} →</button
|
||||
>
|
||||
</div>{/if}
|
||||
</main>
|
||||
{:else}<div class="waiting">
|
||||
<h1>FUJI</h1>
|
||||
<p>Waiting for the expedition…</p>
|
||||
</div>{/if}
|
||||
{#if help}<div class="modal-backdrop" role="presentation">
|
||||
<div class="modal" use:modalFocus role="dialog" aria-modal="true" aria-labelledby="help-title" tabindex="-1">
|
||||
<button class="close" onclick={() => (help = false)} aria-label="Close guide">×</button><span class="eyebrow"
|
||||
>THE ESSENTIALS</span
|
||||
>
|
||||
<h2 id="help-title">Escape together.</h2>
|
||||
<p>
|
||||
Everyone must reach the village. If anyone is caught by lava or loses all stamina, the whole expedition loses.
|
||||
</p>
|
||||
<ol class="guide">
|
||||
<li>
|
||||
<strong>Plan a route.</strong> Move up to three adjacent locations. Longer journeys leave fewer rerolls. Your two
|
||||
seated neighbors must choose different destinations from yours.
|
||||
</li>
|
||||
<li>
|
||||
<strong>Talk, without numbers.</strong> Share intentions and vague impressions. Never reveal exact dice values,
|
||||
counts or averages. During rerolls, stay silent.
|
||||
</li>
|
||||
<li>
|
||||
<strong>Use your equipment.</strong> Its phase is shown beside each item. Dice remain private until everyone is
|
||||
ready to reveal.
|
||||
</li>
|
||||
<li>
|
||||
<strong>Compare on your destination.</strong> Add matching dice. Your total must beat both neighbors. A tie fails.
|
||||
A smaller lead costs more stamina.
|
||||
</li>
|
||||
<li>
|
||||
<strong>Watch the lava.</strong> It advances one step each round. Crossing an eruption marker triggers extra lava
|
||||
immediately.
|
||||
</li>
|
||||
</ol>
|
||||
<button class="primary" onclick={() => (help = false)}>Back to the expedition</button>
|
||||
</div>
|
||||
</div>{/if}
|
||||
{#if newGame}<div class="modal-backdrop" role="presentation">
|
||||
<div class="modal" use:modalFocus role="dialog" aria-modal="true" aria-labelledby="new-title" tabindex="-1">
|
||||
<button class="close" onclick={() => (newGame = false)} aria-label="Close">×</button><span class="eyebrow"
|
||||
>A NEW BEGINNING</span
|
||||
>
|
||||
<h2 id="new-title">Gather your expedition.</h2>
|
||||
<p>This replaces the current local playtest.</p>
|
||||
<label class="field"
|
||||
>Adventurers<select bind:value={newPlayers}
|
||||
><option value={2}>2 players · neutral dice variant</option><option value={3}>3 players</option><option
|
||||
value={4}>4 players</option
|
||||
></select
|
||||
></label
|
||||
><label class="field"
|
||||
>Difficulty<select bind:value={newDifficulty}
|
||||
>{#each [1, 2, 3, 4] as n}<option value={n}>Level {n}</option>{/each}</select
|
||||
></label
|
||||
><label class="field">Expedition seed<input bind:value={newSeed} /></label><button
|
||||
class="primary"
|
||||
onclick={() => {
|
||||
store.restart(newPlayers, newSeed, newDifficulty);
|
||||
newGame = false;
|
||||
inspected = "";
|
||||
}}>Begin expedition <span>→</span></button
|
||||
>
|
||||
</div>
|
||||
</div>{/if}
|
||||
BIN
packages/viewer/src/assets/character-01.webp
Normal file
|
After Width: | Height: | Size: 61 KiB |
BIN
packages/viewer/src/assets/character-02.webp
Normal file
|
After Width: | Height: | Size: 51 KiB |
BIN
packages/viewer/src/assets/character-03.webp
Normal file
|
After Width: | Height: | Size: 53 KiB |
BIN
packages/viewer/src/assets/character-04.webp
Normal file
|
After Width: | Height: | Size: 60 KiB |
BIN
packages/viewer/src/assets/character-05.webp
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
packages/viewer/src/assets/equipment-01.webp
Normal file
|
After Width: | Height: | Size: 40 KiB |
BIN
packages/viewer/src/assets/equipment-02.webp
Normal file
|
After Width: | Height: | Size: 38 KiB |
BIN
packages/viewer/src/assets/equipment-03.webp
Normal file
|
After Width: | Height: | Size: 43 KiB |
BIN
packages/viewer/src/assets/equipment-04.webp
Normal file
|
After Width: | Height: | Size: 36 KiB |
BIN
packages/viewer/src/assets/equipment-05.webp
Normal file
|
After Width: | Height: | Size: 36 KiB |
BIN
packages/viewer/src/assets/equipment-06.webp
Normal file
|
After Width: | Height: | Size: 40 KiB |
BIN
packages/viewer/src/assets/equipment-07.webp
Normal file
|
After Width: | Height: | Size: 36 KiB |
BIN
packages/viewer/src/assets/equipment-08.webp
Normal file
|
After Width: | Height: | Size: 39 KiB |
BIN
packages/viewer/src/assets/equipment-09.webp
Normal file
|
After Width: | Height: | Size: 39 KiB |
BIN
packages/viewer/src/assets/equipment-10.webp
Normal file
|
After Width: | Height: | Size: 34 KiB |
BIN
packages/viewer/src/assets/equipment-11.webp
Normal file
|
After Width: | Height: | Size: 38 KiB |
BIN
packages/viewer/src/assets/equipment-12.webp
Normal file
|
After Width: | Height: | Size: 45 KiB |
BIN
packages/viewer/src/assets/equipment-13.webp
Normal file
|
After Width: | Height: | Size: 34 KiB |
BIN
packages/viewer/src/assets/equipment-14.webp
Normal file
|
After Width: | Height: | Size: 44 KiB |
BIN
packages/viewer/src/assets/equipment-15.webp
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
packages/viewer/src/assets/land-01.webp
Normal file
|
After Width: | Height: | Size: 81 KiB |
BIN
packages/viewer/src/assets/land-02.webp
Normal file
|
After Width: | Height: | Size: 55 KiB |
BIN
packages/viewer/src/assets/land-03.webp
Normal file
|
After Width: | Height: | Size: 47 KiB |
BIN
packages/viewer/src/assets/land-04.webp
Normal file
|
After Width: | Height: | Size: 92 KiB |
BIN
packages/viewer/src/assets/land-05.webp
Normal file
|
After Width: | Height: | Size: 93 KiB |
BIN
packages/viewer/src/assets/land-06.webp
Normal file
|
After Width: | Height: | Size: 78 KiB |
BIN
packages/viewer/src/assets/land-07.webp
Normal file
|
After Width: | Height: | Size: 116 KiB |
BIN
packages/viewer/src/assets/land-08.webp
Normal file
|
After Width: | Height: | Size: 111 KiB |
BIN
packages/viewer/src/assets/land-09.webp
Normal file
|
After Width: | Height: | Size: 92 KiB |
BIN
packages/viewer/src/assets/land-10.webp
Normal file
|
After Width: | Height: | Size: 63 KiB |
BIN
packages/viewer/src/assets/land-11.webp
Normal file
|
After Width: | Height: | Size: 120 KiB |
BIN
packages/viewer/src/assets/land-12.webp
Normal file
|
After Width: | Height: | Size: 117 KiB |
BIN
packages/viewer/src/assets/land-13.webp
Normal file
|
After Width: | Height: | Size: 130 KiB |
BIN
packages/viewer/src/assets/land-14.webp
Normal file
|
After Width: | Height: | Size: 130 KiB |
BIN
packages/viewer/src/assets/land-15.webp
Normal file
|
After Width: | Height: | Size: 73 KiB |
BIN
packages/viewer/src/assets/land-16.webp
Normal file
|
After Width: | Height: | Size: 105 KiB |
BIN
packages/viewer/src/assets/land-17.webp
Normal file
|
After Width: | Height: | Size: 114 KiB |
BIN
packages/viewer/src/assets/land-18.webp
Normal file
|
After Width: | Height: | Size: 78 KiB |
BIN
packages/viewer/src/assets/land-19.webp
Normal file
|
After Width: | Height: | Size: 85 KiB |
BIN
packages/viewer/src/assets/land-20.webp
Normal file
|
After Width: | Height: | Size: 99 KiB |
BIN
packages/viewer/src/assets/land-21.webp
Normal file
|
After Width: | Height: | Size: 89 KiB |
BIN
packages/viewer/src/assets/land-22.webp
Normal file
|
After Width: | Height: | Size: 102 KiB |
BIN
packages/viewer/src/assets/land-23.webp
Normal file
|
After Width: | Height: | Size: 128 KiB |
BIN
packages/viewer/src/assets/land-24.webp
Normal file
|
After Width: | Height: | Size: 100 KiB |
BIN
packages/viewer/src/assets/land-25.webp
Normal file
|
After Width: | Height: | Size: 88 KiB |
BIN
packages/viewer/src/assets/land-26.webp
Normal file
|
After Width: | Height: | Size: 82 KiB |
BIN
packages/viewer/src/assets/land-27.webp
Normal file
|
After Width: | Height: | Size: 92 KiB |
BIN
packages/viewer/src/assets/land-28.webp
Normal file
|
After Width: | Height: | Size: 60 KiB |
BIN
packages/viewer/src/assets/land-29.webp
Normal file
|
After Width: | Height: | Size: 86 KiB |
BIN
packages/viewer/src/assets/land-30.webp
Normal file
|
After Width: | Height: | Size: 93 KiB |
BIN
packages/viewer/src/assets/land-31.webp
Normal file
|
After Width: | Height: | Size: 116 KiB |
BIN
packages/viewer/src/assets/land-32.webp
Normal file
|
After Width: | Height: | Size: 90 KiB |
BIN
packages/viewer/src/assets/land-33.webp
Normal file
|
After Width: | Height: | Size: 82 KiB |
BIN
packages/viewer/src/assets/skill-01.webp
Normal file
|
After Width: | Height: | Size: 47 KiB |
BIN
packages/viewer/src/assets/skill-02.webp
Normal file
|
After Width: | Height: | Size: 43 KiB |
BIN
packages/viewer/src/assets/skill-03.webp
Normal file
|
After Width: | Height: | Size: 46 KiB |
BIN
packages/viewer/src/assets/skill-04.webp
Normal file
|
After Width: | Height: | Size: 46 KiB |
BIN
packages/viewer/src/assets/skill-05.webp
Normal file
|
After Width: | Height: | Size: 46 KiB |
BIN
packages/viewer/src/assets/skill-06.webp
Normal file
|
After Width: | Height: | Size: 45 KiB |
117
packages/viewer/src/dev.ts
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
import { mount } from "svelte";
|
||||
import App from "./App.svelte";
|
||||
import { Store } from "./lib/store.svelte";
|
||||
import {
|
||||
initGame,
|
||||
applyMove,
|
||||
stripSecret,
|
||||
activePlayers,
|
||||
paths,
|
||||
terrain,
|
||||
cell,
|
||||
total,
|
||||
SKILLS,
|
||||
hasSkill,
|
||||
activeDice,
|
||||
face,
|
||||
matches,
|
||||
type State,
|
||||
type Move,
|
||||
} from "fuji-engine";
|
||||
import "./lib/theme.css";
|
||||
const store = new Store();
|
||||
store.local = true;
|
||||
store.seat = 0;
|
||||
let game: State;
|
||||
const saved = localStorage.getItem("fuji-dev-v1");
|
||||
try {
|
||||
game = saved ? JSON.parse(saved) : initGame(3, {}, "first-light");
|
||||
if (game.schemaVersion !== 1) throw Error("Old save");
|
||||
} catch {
|
||||
game = initGame(3, {}, "first-light");
|
||||
}
|
||||
function publish() {
|
||||
localStorage.setItem("fuji-dev-v1", JSON.stringify(game));
|
||||
store.receive(stripSecret(game, store.seat));
|
||||
}
|
||||
store.send = (move) => {
|
||||
game = applyMove(game, move, store.seat!);
|
||||
publish();
|
||||
};
|
||||
store.selectSeat = (seat) => {
|
||||
store.seat = seat;
|
||||
store.error = "";
|
||||
publish();
|
||||
};
|
||||
store.restart = (players, seed, difficulty) => {
|
||||
game = initGame(players, { difficulty }, seed);
|
||||
store.seat = 0;
|
||||
publish();
|
||||
};
|
||||
function chooseMove(seat: number): Move {
|
||||
const p = game.players[seat]!;
|
||||
if (game.pending) {
|
||||
if (game.pending.kind === "lend") return { action: "decline" };
|
||||
return { action: "respond", ids: [activeDice(p)[0]!.id] };
|
||||
}
|
||||
if (p.pendingInjuries) {
|
||||
const injury = ["arm", "eye", "amnesia", "leg"].find((i) => !p.injuries.includes(i as never))!;
|
||||
return { action: "injury", injury, die: p.dice.find((d) => d.owner === seat && !d.aside)?.id };
|
||||
}
|
||||
if (game.phase === "setup")
|
||||
return { action: "setup", keep: p.cards.slice(0, SKILLS[p.skill].keep).map((c) => c.id), drop: p.dice.at(-1)?.id };
|
||||
if (game.phase === "planning") {
|
||||
const choices = Object.values(paths(game, seat)).filter(
|
||||
(path) => !game.players.some((q, i) => i !== seat && q.ready && q.path.at(-1) === path.at(-1))
|
||||
);
|
||||
const score = (path: string[]) => {
|
||||
const c = cell(game, path.at(-1)!);
|
||||
const closestVillage = Math.min(
|
||||
...game.board
|
||||
.filter((c) => terrain(c.terrain).kind === "village")
|
||||
.map((v) => Math.abs(c.x - v.x) + Math.abs(c.y - v.y))
|
||||
);
|
||||
return (
|
||||
total(p, c.terrain) * 0.65 -
|
||||
closestVillage * 2 +
|
||||
(terrain(c.terrain).kind === "village" ? 8 : 0) +
|
||||
(c.equipment ? 1 : 0) -
|
||||
(c.eruption ? 2 : 0)
|
||||
);
|
||||
};
|
||||
choices.sort((a, b) => score(b) - score(a));
|
||||
const best = choices[0];
|
||||
if (!best) throw Error("No available destination.");
|
||||
if (best.at(-1) !== p.path.at(-1)) return { action: "plan", path: best };
|
||||
return { action: "ready" };
|
||||
}
|
||||
if (game.phase === "reroll") {
|
||||
const r = terrain(cell(game, p.path.at(-1)!).terrain).requirement;
|
||||
const ids = activeDice(p)
|
||||
.filter((d) => !matches(face(d), r))
|
||||
.map((d) => d.id);
|
||||
return p.rerolls && ids.length ? { action: "reroll", ids } : { action: "finishRerolls" };
|
||||
}
|
||||
if (game.phase === "equipment") return { action: "ready" };
|
||||
if (game.phase === "movement") {
|
||||
if (game.activeResolution === null) return { action: "beginMovement" };
|
||||
if (game.activeResolution === seat) return { action: "resolve" };
|
||||
return { action: "bar" };
|
||||
}
|
||||
return { action: "erupt" };
|
||||
}
|
||||
store.teammateStep = () => {
|
||||
try {
|
||||
const available = activePlayers(game).filter(
|
||||
(i) => !["planning", "equipment"].includes(game.phase) || !game.players[i]!.ready
|
||||
);
|
||||
const seat = available.find((i) => i !== store.seat) ?? available[0];
|
||||
if (seat === undefined) return;
|
||||
game = applyMove(game, chooseMove(seat), seat);
|
||||
publish();
|
||||
} catch (e) {
|
||||
store.error = String(e);
|
||||
}
|
||||
};
|
||||
publish();
|
||||
mount(App, { target: document.querySelector("#app")!, props: { store } });
|
||||
112
packages/viewer/src/lib/Die.svelte
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
<script lang="ts">
|
||||
import { face, type Die } from "fuji-engine";
|
||||
let {
|
||||
die,
|
||||
selected = false,
|
||||
relevant = false,
|
||||
disabled = false,
|
||||
onclick = () => {},
|
||||
}: { die: Die; selected?: boolean; relevant?: boolean; disabled?: boolean; onclick?: () => void } = $props();
|
||||
const f = $derived(face(die));
|
||||
const layouts: Record<number, number[]> = {
|
||||
1: [4],
|
||||
2: [0, 8],
|
||||
3: [0, 4, 8],
|
||||
4: [0, 2, 6, 8],
|
||||
5: [0, 2, 4, 6, 8],
|
||||
6: [0, 2, 3, 5, 6, 8],
|
||||
};
|
||||
</script>
|
||||
|
||||
<button
|
||||
class="die"
|
||||
class:chosen={selected}
|
||||
class:relevant
|
||||
class:aside={die.aside}
|
||||
class:hidden={!die.face}
|
||||
style:--die-color={die.face ? { blue: "#82ccdb", pink: "#e16d9a", yellow: "#f2cd5d" }[f.color] : "#27433c"}
|
||||
{disabled}
|
||||
{onclick}
|
||||
aria-label={die.face ? `${f.color} ${die.face}${die.aside ? ", set aside" : ""}` : "Hidden die"}
|
||||
aria-pressed={selected}
|
||||
>
|
||||
{#if die.face}<span class="pips" aria-hidden="true"
|
||||
>{#each Array(9) as _, i}<i class:filled={layouts[die.face]?.includes(i)}></i>{/each}</span
|
||||
><span class="die-caption">{f.color}</span>{:else}<span aria-hidden="true">?</span>{/if}
|
||||
</button>
|
||||
|
||||
<style>
|
||||
.die {
|
||||
position: relative;
|
||||
width: 54px;
|
||||
height: 58px;
|
||||
border-radius: 11px;
|
||||
background: var(--die-color);
|
||||
border: 2px solid #ffffff23;
|
||||
color: #162b28;
|
||||
box-shadow:
|
||||
inset 0 -5px 0 #0002,
|
||||
0 3px 10px #0003;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
cursor: pointer;
|
||||
transition:
|
||||
transform 0.16s,
|
||||
border-color 0.16s;
|
||||
flex: none;
|
||||
padding: 7px 9px 13px;
|
||||
}
|
||||
.die:hover:not(:disabled) {
|
||||
transform: translateY(-3px);
|
||||
}
|
||||
.die:disabled {
|
||||
cursor: default;
|
||||
opacity: 1;
|
||||
}
|
||||
.die.chosen {
|
||||
transform: translateY(-7px);
|
||||
border-color: #fff7cd;
|
||||
outline: 2px solid #fff7cd;
|
||||
outline-offset: 3px;
|
||||
}
|
||||
.die.relevant:not(.chosen) {
|
||||
box-shadow:
|
||||
inset 0 -5px 0 #0002,
|
||||
0 0 0 2px #dcecb96b;
|
||||
}
|
||||
.die.aside {
|
||||
opacity: 0.5;
|
||||
transform: scale(0.85);
|
||||
}
|
||||
.pips {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 6px);
|
||||
grid-template-rows: repeat(3, 6px);
|
||||
gap: 4px;
|
||||
}
|
||||
.pips i {
|
||||
border-radius: 50%;
|
||||
background: transparent;
|
||||
}
|
||||
.pips i.filled {
|
||||
background: #18372f;
|
||||
}
|
||||
.die-caption {
|
||||
position: absolute;
|
||||
bottom: 3px;
|
||||
font-size: 8px;
|
||||
line-height: 1;
|
||||
font-weight: 750;
|
||||
letter-spacing: 0.035em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
.hidden {
|
||||
border: 1px solid #ffffff14;
|
||||
box-shadow: none;
|
||||
color: #b4c6b6;
|
||||
}
|
||||
.hidden span {
|
||||
font-family: Georgia, serif;
|
||||
font-size: 22px;
|
||||
}
|
||||
</style>
|
||||
413
packages/viewer/src/lib/Landscape.svelte
Normal file
|
|
@ -0,0 +1,413 @@
|
|||
<script lang="ts">
|
||||
import { terrain, cell, distance, threatened, CHARACTER_COLORS, requirementLabel, type View } from "fuji-engine";
|
||||
import { art } from "./assets";
|
||||
let {
|
||||
state,
|
||||
seat,
|
||||
route = [],
|
||||
selected = "",
|
||||
reachable = [],
|
||||
onclick,
|
||||
oninspect,
|
||||
}: {
|
||||
state: View;
|
||||
seat?: number;
|
||||
route?: string[];
|
||||
selected?: string;
|
||||
reachable?: string[];
|
||||
onclick: (id: string) => void;
|
||||
oninspect: (id: string) => void;
|
||||
} = $props();
|
||||
const danger = $derived(threatened(state));
|
||||
const x = (id: string) => 58 + cell(state, id).x * 100;
|
||||
const y = (id: string) => 54 + cell(state, id).y * 84;
|
||||
const edges = $derived(
|
||||
state.board.flatMap((a) =>
|
||||
state.board.filter((b) => distance(a, b) === 1 && (b.x > a.x || b.y > a.y)).map((b) => ({ a, b }))
|
||||
)
|
||||
);
|
||||
function badge(id: number) {
|
||||
const r = terrain(id).requirement;
|
||||
const c = r.colors?.length === 3 ? "" : (r.colors?.map((c) => c[0]!.toUpperCase()).join("+") ?? "");
|
||||
const v = r.values?.join("/") ?? "";
|
||||
return [c, r.combine === "or" ? "or" : "", r.parity === "odd" ? "odd" : r.parity === "even" ? "even" : "", v]
|
||||
.filter(Boolean)
|
||||
.join(" ");
|
||||
}
|
||||
const routeLine = $derived(route.map((id) => `${x(id)},${y(id)}`).join(" "));
|
||||
</script>
|
||||
|
||||
<div class="landscape" style:--landscape-art={`url(${art("land", 21)})`}>
|
||||
<div class="scene-caption">
|
||||
<span class="eyebrow">THE FUJI TRAIL</span><span
|
||||
>Scenario 01 <span class="dot">·</span> Level {state.difficulty}</span
|
||||
>
|
||||
</div>
|
||||
<div class="map-scroll">
|
||||
<svg viewBox="0 0 835 630" class="map" aria-label="Expedition map. Choose a location to inspect or plan a journey.">
|
||||
<defs>
|
||||
<radialGradient id="feather"
|
||||
><stop offset="65%" stop-color="white" /><stop offset="100%" stop-color="black" /></radialGradient
|
||||
>
|
||||
<mask id="land-mask" maskContentUnits="objectBoundingBox"
|
||||
><rect width="1" height="1" fill="url(#feather)" /></mask
|
||||
>
|
||||
<linearGradient id="lava-gradient" x2="1" y2="1"
|
||||
><stop stop-color="#ffcd64" /><stop offset=".45" stop-color="#e45931" /><stop
|
||||
offset="1"
|
||||
stop-color="#751f21"
|
||||
/></linearGradient
|
||||
>
|
||||
<filter id="glow"><feGaussianBlur stdDeviation="4" /></filter>
|
||||
</defs>
|
||||
<text x="405" y="9" class="map-region">THE VILLAGE</text>
|
||||
<text x="45" y="607" class="map-note">ORTHOGONAL PATHS · ESCAPE TOGETHER</text>
|
||||
{#each edges as { a, b }}<line
|
||||
x1={x(a.id)}
|
||||
y1={y(a.id)}
|
||||
x2={x(b.id)}
|
||||
y2={y(b.id)}
|
||||
class="trail"
|
||||
class:burnt={a.lava || b.lava}
|
||||
/>{/each}
|
||||
{#each state.board as c (c.id)}
|
||||
{@const data = terrain(c.terrain)}
|
||||
<g
|
||||
class="location"
|
||||
class:reachable={reachable.includes(c.id)}
|
||||
class:selected={selected === c.id}
|
||||
class:lava={c.lava}
|
||||
role="button"
|
||||
tabindex="0"
|
||||
aria-label={`${data.name}${c.lava ? ", covered in lava" : ""}${c.equipment ? ", equipment here" : ""}${danger.includes(c.id) ? ", threatened by the next eruption" : ""}`}
|
||||
onclick={() => onclick(c.id)}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === "Enter" || e.key === " ") {
|
||||
e.preventDefault();
|
||||
onclick(c.id);
|
||||
}
|
||||
}}
|
||||
onmouseenter={() => oninspect(c.id)}
|
||||
onfocus={() => oninspect(c.id)}
|
||||
>
|
||||
<rect x={x(c.id) - 44} y={y(c.id) - 35} width="88" height="70" rx="13" class="land-base" />
|
||||
<image
|
||||
href={art("land", c.lava ? 1 : c.terrain)}
|
||||
x={x(c.id) - 47}
|
||||
y={y(c.id) - 39}
|
||||
width="94"
|
||||
height="78"
|
||||
preserveAspectRatio="xMidYMid slice"
|
||||
mask="url(#land-mask)"
|
||||
class="tile-art"
|
||||
/>
|
||||
{#if c.lava}<path
|
||||
d={`M ${x(c.id) - 35} ${y(c.id) + 15} l 20 -12 -5 -14 25 4 18 -16 M ${x(c.id) + 5} ${y(c.id) - 8} l 12 18 -8 15`}
|
||||
class="lava-crack"
|
||||
/>{/if}
|
||||
<rect x={x(c.id) - 44} y={y(c.id) - 35} width="88" height="70" rx="13" class="location-ring" />
|
||||
{#if reachable.includes(c.id) && !c.lava}<circle
|
||||
cx={x(c.id)}
|
||||
cy={y(c.id) + 31}
|
||||
r="3"
|
||||
class="reachable-dot"
|
||||
/>{/if}
|
||||
{#if c.equipment && !c.lava}<g transform={`translate(${x(c.id) + 29},${y(c.id) - 25})`}
|
||||
><circle r="10" class="equipment-dot" /><path
|
||||
d="M-4 -2h8v6h-8z M-2 -2v-3h4v3"
|
||||
class="equipment-icon"
|
||||
/></g
|
||||
>{/if}
|
||||
{#if c.eruption && !c.lava}<g transform={`translate(${x(c.id) - 29},${y(c.id) - 25})`}
|
||||
><path d="M0 -10 10 8H-10Z" class="eruption-dot" /><text y="5" text-anchor="middle" class="warning-mark"
|
||||
>!</text
|
||||
></g
|
||||
>{/if}
|
||||
{#if danger.includes(c.id)}<rect
|
||||
x={x(c.id) - 44}
|
||||
y={y(c.id) - 35}
|
||||
width="88"
|
||||
height="70"
|
||||
rx="13"
|
||||
class="danger-ring"
|
||||
/>{/if}
|
||||
{#if !c.lava && ["land", "village"].includes(data.kind)}<rect
|
||||
x={x(c.id) - 40}
|
||||
y={y(c.id) + 17}
|
||||
width="80"
|
||||
height="18"
|
||||
rx="4"
|
||||
fill="#112820e6"
|
||||
/><text x={x(c.id)} y={y(c.id) + 30} text-anchor="middle" class="requirement-badge">{badge(c.terrain)}</text
|
||||
>{/if}
|
||||
{#if data.reroll && !c.lava}<text x={x(c.id) - 34} y={y(c.id) - 16} class="reroll-mark">↻</text>{/if}
|
||||
</g>
|
||||
{/each}
|
||||
{#if route.length > 1}<polyline points={routeLine} class="route-shadow" /><polyline
|
||||
points={routeLine}
|
||||
class="route-line"
|
||||
/>{/if}
|
||||
{#each state.players as p, i (i)}
|
||||
{#if p.ready && state.phase === "planning" && p.path.length}
|
||||
<circle
|
||||
cx={x(p.path.at(-1)!)}
|
||||
cy={y(p.path.at(-1)!)}
|
||||
r="25"
|
||||
fill="none"
|
||||
stroke={CHARACTER_COLORS[p.character]}
|
||||
stroke-width="2"
|
||||
stroke-dasharray="3 5"
|
||||
/>
|
||||
{/if}
|
||||
{@const occupants = state.players.map((q, j) => (q.position === p.position ? j : -1)).filter((j) => j >= 0)}
|
||||
{@const offset = (occupants.indexOf(i) - (occupants.length - 1) / 2) * 27}
|
||||
<g class="traveler" style:transform={`translate(${x(p.position) + offset}px,${y(p.position)}px)`}>
|
||||
<circle r="19" fill="#091e1b" stroke={CHARACTER_COLORS[p.character]} stroke-width={i === seat ? 3 : 2} />
|
||||
<text text-anchor="middle" y="6" fill={CHARACTER_COLORS[p.character]} class="traveler-number">{i + 1}</text>
|
||||
{#if i === seat}<path d="M-4 -28H4L0 -22Z" fill="#f4d888" />{/if}
|
||||
</g>
|
||||
{/each}
|
||||
</svg>
|
||||
</div>
|
||||
<div class="scene-legend">
|
||||
<span><i class="legend-line"></i>Your route</span><span><i class="legend-danger"></i>Next eruption</span><span
|
||||
class="legend-end"
|
||||
>{state.players.filter((p) => terrain(cell(state, p.position).terrain).kind === "village").length} / {state
|
||||
.players.length} in the village</span
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.landscape {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
background: #142f29;
|
||||
isolation: isolate;
|
||||
border: 1px solid #c9ddac16;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.landscape:before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background:
|
||||
linear-gradient(120deg, #132e2adb, #122c28ea),
|
||||
var(--landscape-art) center/cover;
|
||||
z-index: -1;
|
||||
}
|
||||
.scene-caption {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 23px 26px 0;
|
||||
font-size: 12px;
|
||||
color: #a1b5a4;
|
||||
}
|
||||
.dot {
|
||||
margin: 0 5px;
|
||||
color: #cfb873;
|
||||
}
|
||||
.map {
|
||||
width: 100%;
|
||||
height: clamp(390px, calc(100vh - 430px), 610px);
|
||||
display: block;
|
||||
}
|
||||
.requirement-badge {
|
||||
font: 600 11px var(--font-ui);
|
||||
fill: #e6e2b9;
|
||||
}
|
||||
.map-region {
|
||||
font: 11px var(--font-ui);
|
||||
letter-spacing: 5px;
|
||||
fill: #c6c88788;
|
||||
}
|
||||
.map-note {
|
||||
font: 9px var(--font-ui);
|
||||
letter-spacing: 2px;
|
||||
fill: #a1b5a44d;
|
||||
}
|
||||
.trail {
|
||||
stroke: #b7bd8450;
|
||||
stroke-width: 3;
|
||||
stroke-linecap: round;
|
||||
stroke-dasharray: 2 7;
|
||||
}
|
||||
.trail.burnt {
|
||||
stroke: #d8734555;
|
||||
}
|
||||
.land-base {
|
||||
fill: #213e2e;
|
||||
}
|
||||
.tile-art {
|
||||
opacity: 0.86;
|
||||
transition: opacity 0.2s;
|
||||
}
|
||||
.location {
|
||||
cursor: pointer;
|
||||
outline: none;
|
||||
}
|
||||
.location-ring {
|
||||
fill: none;
|
||||
stroke: #dbc47d25;
|
||||
stroke-width: 1;
|
||||
transition:
|
||||
stroke 0.15s,
|
||||
stroke-width 0.15s;
|
||||
}
|
||||
.location:hover .location-ring,
|
||||
.location:focus .location-ring {
|
||||
stroke: #f2d49a;
|
||||
stroke-width: 2;
|
||||
}
|
||||
.location:hover .tile-art {
|
||||
opacity: 1;
|
||||
}
|
||||
.location.selected .location-ring {
|
||||
stroke: #f9df99;
|
||||
stroke-width: 2.5;
|
||||
}
|
||||
.location.selected .tile-art {
|
||||
opacity: 1;
|
||||
}
|
||||
.location.reachable .location-ring {
|
||||
stroke: #c3d6a865;
|
||||
}
|
||||
.reachable-dot {
|
||||
fill: #e7db99;
|
||||
}
|
||||
.equipment-dot {
|
||||
fill: #dfc176;
|
||||
stroke: #192f26;
|
||||
stroke-width: 2;
|
||||
}
|
||||
.equipment-icon {
|
||||
fill: none;
|
||||
stroke: #29392a;
|
||||
stroke-width: 1.5;
|
||||
stroke-linejoin: round;
|
||||
}
|
||||
.eruption-dot {
|
||||
fill: #e88a54;
|
||||
stroke: #482c27;
|
||||
stroke-width: 1.5;
|
||||
}
|
||||
.warning-mark {
|
||||
font: bold 12px var(--font-ui);
|
||||
fill: #452c25;
|
||||
}
|
||||
.reroll-mark {
|
||||
font:
|
||||
22px Georgia,
|
||||
serif;
|
||||
fill: #e8edbb;
|
||||
}
|
||||
.danger-ring {
|
||||
fill: none;
|
||||
stroke: #eb8c5e;
|
||||
stroke-width: 2;
|
||||
stroke-dasharray: 4 5;
|
||||
animation: pulse 3s ease-in-out infinite;
|
||||
pointer-events: none;
|
||||
}
|
||||
.lava .tile-art {
|
||||
opacity: 0.65;
|
||||
}
|
||||
.lava-crack {
|
||||
fill: none;
|
||||
stroke: #f5ae4a;
|
||||
stroke-width: 2;
|
||||
stroke-linecap: round;
|
||||
animation: pulse 4s ease-in-out infinite;
|
||||
}
|
||||
.route-shadow {
|
||||
fill: none;
|
||||
stroke: #293d28;
|
||||
stroke-width: 7;
|
||||
stroke-linejoin: round;
|
||||
pointer-events: none;
|
||||
}
|
||||
.route-line {
|
||||
fill: none;
|
||||
stroke: #f1d584;
|
||||
stroke-width: 3;
|
||||
stroke-linejoin: round;
|
||||
stroke-dasharray: 6 6;
|
||||
animation: route-flow 3s linear infinite;
|
||||
pointer-events: none;
|
||||
}
|
||||
.traveler {
|
||||
transition: transform 0.65s cubic-bezier(0.22, 0.61, 0.36, 1);
|
||||
pointer-events: none;
|
||||
filter: drop-shadow(0 4px 3px #0007);
|
||||
}
|
||||
.traveler-number {
|
||||
font: 600 17px var(--font-ui);
|
||||
}
|
||||
.scene-legend {
|
||||
padding: 0 25px 20px;
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
color: #a7b9a8;
|
||||
font-size: 12px;
|
||||
align-items: center;
|
||||
}
|
||||
.scene-legend span {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
}
|
||||
.legend-line {
|
||||
width: 20px;
|
||||
border-top: 2px dashed #f1d584;
|
||||
}
|
||||
.legend-danger {
|
||||
width: 9px;
|
||||
height: 9px;
|
||||
border: 1px dashed #eb8c5e;
|
||||
border-radius: 2px;
|
||||
}
|
||||
.legend-end {
|
||||
margin-left: auto;
|
||||
color: #d7d7a7;
|
||||
}
|
||||
@keyframes pulse {
|
||||
50% {
|
||||
opacity: 0.5;
|
||||
}
|
||||
}
|
||||
@keyframes route-flow {
|
||||
to {
|
||||
stroke-dashoffset: -24;
|
||||
}
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.route-line,
|
||||
.danger-ring,
|
||||
.lava-crack {
|
||||
animation: none;
|
||||
}
|
||||
.traveler {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
@media (max-width: 650px) {
|
||||
.map-scroll {
|
||||
overflow-x: auto;
|
||||
}
|
||||
.map {
|
||||
min-width: 610px;
|
||||
height: auto;
|
||||
}
|
||||
.scene-caption {
|
||||
padding: 16px 16px 0;
|
||||
}
|
||||
.scene-legend {
|
||||
padding: 8px 16px 16px;
|
||||
gap: 12px;
|
||||
}
|
||||
.legend-end {
|
||||
display: none !important;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
7
packages/viewer/src/lib/assets.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
const files = import.meta.glob(
|
||||
["../assets/land-*.webp", "../assets/equipment-*.webp", "../assets/character-0[1-4].webp"],
|
||||
{ eager: true, query: "?url", import: "default" }
|
||||
) as Record<string, string>;
|
||||
export function art(kind: string, id: number): string {
|
||||
return files[`../assets/${kind}-${String(id).padStart(2, "0")}.webp`] ?? "";
|
||||
}
|
||||
34
packages/viewer/src/lib/emitter.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
export type Listener<T = unknown> = (payload: T) => void;
|
||||
|
||||
export class Emitter {
|
||||
private listeners = new Map<string, Set<Listener>>();
|
||||
|
||||
on<T = unknown>(event: string, listener: Listener<T>): () => void {
|
||||
let set = this.listeners.get(event);
|
||||
if (!set) {
|
||||
set = new Set();
|
||||
this.listeners.set(event, set);
|
||||
}
|
||||
const wrapped = listener as Listener;
|
||||
set.add(wrapped);
|
||||
return () => set.delete(wrapped);
|
||||
}
|
||||
|
||||
once<T = unknown>(event: string, listener: Listener<T>): () => void {
|
||||
const off = this.on<T>(event, (payload) => {
|
||||
off();
|
||||
listener(payload);
|
||||
});
|
||||
return off;
|
||||
}
|
||||
|
||||
emit<T = unknown>(event: string, payload?: T): void {
|
||||
for (const listener of this.listeners.get(event) ?? []) {
|
||||
try {
|
||||
listener(payload);
|
||||
} catch (error) {
|
||||
console.error(`[fuji-viewer] listener for "${event}" failed`, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
26
packages/viewer/src/lib/store.svelte.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import type { View, Move } from "fuji-engine";
|
||||
export class Store {
|
||||
state: View | null = $state(null);
|
||||
seat: number | undefined = $state(undefined);
|
||||
error = $state("");
|
||||
waiting = $state(false);
|
||||
local = $state(false);
|
||||
send: (move: Move) => void = () => {};
|
||||
selectSeat: (seat: number) => void = () => {};
|
||||
restart: (players: number, seed: string, difficulty: number) => void = () => {};
|
||||
teammateStep: () => void = () => {};
|
||||
dispatch(move: Move) {
|
||||
this.error = "";
|
||||
this.waiting = true;
|
||||
try {
|
||||
this.send(JSON.parse(JSON.stringify(move)));
|
||||
} catch (e) {
|
||||
this.error = e instanceof Error ? e.message : String(e);
|
||||
this.waiting = false;
|
||||
}
|
||||
}
|
||||
receive(s: View) {
|
||||
this.state = s;
|
||||
this.waiting = false;
|
||||
}
|
||||
}
|
||||
1207
packages/viewer/src/lib/theme.css
Normal file
34
packages/viewer/src/viewer.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import { mount, tick } from "svelte";
|
||||
import App from "./App.svelte";
|
||||
import { Store } from "./lib/store.svelte";
|
||||
import { Emitter } from "./lib/emitter";
|
||||
import type { View } from "fuji-engine";
|
||||
import "./lib/theme.css";
|
||||
export function launch(selector: string) {
|
||||
const target = document.querySelector(selector);
|
||||
if (!target) throw Error("Viewer mount point not found.");
|
||||
const events = new Emitter();
|
||||
const store = new Store();
|
||||
let ready = false;
|
||||
store.send = (move) => events.emit("move", move);
|
||||
events.on<View>("state", async (state) => {
|
||||
store.receive(state);
|
||||
events.emit(
|
||||
"replaceLog",
|
||||
state.log.map((e) => e.text)
|
||||
);
|
||||
await tick();
|
||||
if (!ready) {
|
||||
ready = true;
|
||||
setTimeout(() => events.emit("ready"), 0);
|
||||
}
|
||||
});
|
||||
events.on<{ index?: number }>("player", (p) => {
|
||||
store.seat = p?.index;
|
||||
});
|
||||
events.on("state:updated", () => events.emit("fetchState"));
|
||||
events.on("gamelog", () => events.emit("fetchState"));
|
||||
mount(App, { target, props: { store } });
|
||||
return events;
|
||||
}
|
||||
if (typeof window !== "undefined") (window as unknown as { fuji: unknown }).fuji = { launch };
|
||||
1
packages/viewer/svelte.config.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
export default {};
|
||||
21
packages/viewer/tsconfig.json
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
||||
"strict": true,
|
||||
"noUncheckedIndexedAccess": true,
|
||||
"noImplicitOverride": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"types": ["vite/client"],
|
||||
"noEmit": true,
|
||||
"allowJs": true,
|
||||
"checkJs": false,
|
||||
"isolatedModules": true,
|
||||
"resolveJsonModule": true,
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.svelte", "src/**/*.svelte.ts", "vite.config.ts"]
|
||||
}
|
||||
10
packages/viewer/vite.config.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
||||
import { defineConfig } from "vite";
|
||||
export default defineConfig({
|
||||
plugins: [svelte()],
|
||||
build: {
|
||||
cssCodeSplit: false,
|
||||
lib: { entry: "src/viewer.ts", name: "fuji", formats: ["iife"], fileName: () => "fuji-viewer.iife.js" },
|
||||
rolldownOptions: { output: { assetFileNames: "fuji-viewer.[ext]" } },
|
||||
},
|
||||
});
|
||||
1008
pnpm-lock.yaml
generated
Normal file
2
pnpm-workspace.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
packages:
|
||||
- packages/*
|
||||
27
scripts/extract-assets.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
"""Extract licensed production artwork. Requires Poppler and Pillow.
|
||||
Usage: python scripts/extract-assets.py /path/to/extracted/archives
|
||||
"""
|
||||
import sys,subprocess,tempfile
|
||||
from pathlib import Path
|
||||
from PIL import Image
|
||||
source=Path(sys.argv[1]); dest=Path(__file__).resolve().parents[1]/'packages/viewer/src/assets';dest.mkdir(parents=True,exist_ok=True)
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
pdf=source/'independent/Cards/fuji_land_front_Print3.pdf'
|
||||
rows=subprocess.check_output(['pdfimages','-list',str(pdf)],text=True).splitlines()[2:]
|
||||
subprocess.run(['pdfimages','-png',str(pdf),tmp+'/land'],check=True)
|
||||
selected={}
|
||||
for row in rows:
|
||||
f=row.split()
|
||||
if len(f)<6 or f[2]!='image':continue
|
||||
page,num,w,h=int(f[0]),int(f[1]),int(f[3]),int(f[4])
|
||||
if w<500 or h<500 or page in selected:continue
|
||||
selected[page]=num
|
||||
im=Image.open(f'{tmp}/land-{num:03}.png').convert('RGB')
|
||||
im.thumbnail((800,800))
|
||||
im.save(dest/f'land-{page:02}.webp',quality=82)
|
||||
for name,file in [('character','en/Cards/fuji_character_cards_Front_E.pdf'),('equipment','en/Cards/fuji_equipment_cards_Front_E.pdf'),('skill','en/Cards/fuji_skill_cards_Front_E.pdf')]:
|
||||
subprocess.run(['pdftoppm','-scale-to','650','-png',str(source/file),tmp+'/'+name],check=True,stderr=subprocess.DEVNULL)
|
||||
for page,p in enumerate(sorted(Path(tmp).glob(name+'-*.png')),1):
|
||||
im=Image.open(p).convert('RGB');margin=round(im.width*14.17/212.598) if name!='equipment' else round(im.width*8.5/201.26)
|
||||
im.crop((margin,margin,im.width-margin,im.height-margin)).save(dest/f'{name}-{page:02}.webp',quality=88)
|
||||
print('Extracted',len(list(dest.glob('*.webp'))),'web assets')
|
||||
90
scripts/simulate.mjs
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
import {
|
||||
initGame,
|
||||
applyMove,
|
||||
activePlayers,
|
||||
paths,
|
||||
total,
|
||||
terrain,
|
||||
cell,
|
||||
SKILLS,
|
||||
activeDice,
|
||||
matches,
|
||||
face,
|
||||
replay,
|
||||
} from "../packages/engine/dist/index.js";
|
||||
import assert from "node:assert/strict";
|
||||
function choose(s, seat) {
|
||||
const p = s.players[seat];
|
||||
if (s.pending)
|
||||
return s.pending.kind === "lend" ? { action: "decline" } : { action: "respond", ids: [activeDice(p)[0].id] };
|
||||
if (p.pendingInjuries) {
|
||||
const injury = ["arm", "eye", "amnesia", "leg"].find((i) => !p.injuries.includes(i));
|
||||
return { action: "injury", injury, die: p.dice.find((d) => d.owner === seat)?.id };
|
||||
}
|
||||
switch (s.phase) {
|
||||
case "setup":
|
||||
return { action: "setup", keep: p.cards.slice(0, SKILLS[p.skill].keep).map((c) => c.id), drop: p.dice.at(-1).id };
|
||||
case "planning": {
|
||||
const choices = Object.values(paths(s, seat)).filter(
|
||||
(path) => !s.players.some((q, i) => i !== seat && q.ready && q.path.at(-1) === path.at(-1))
|
||||
);
|
||||
const score = (path) => {
|
||||
const c = cell(s, path.at(-1));
|
||||
const dist = Math.min(
|
||||
...s.board
|
||||
.filter((c) => terrain(c.terrain).kind === "village")
|
||||
.map((v) => Math.abs(c.x - v.x) + Math.abs(c.y - v.y))
|
||||
);
|
||||
return total(p, c.terrain) * 0.65 - dist * 2;
|
||||
};
|
||||
choices.sort((a, b) => score(b) - score(a));
|
||||
const best = choices[0];
|
||||
if (!best) throw Error("No path");
|
||||
return best.at(-1) !== p.path.at(-1) ? { action: "plan", path: best } : { action: "ready" };
|
||||
}
|
||||
case "reroll": {
|
||||
const ids = activeDice(p)
|
||||
.filter((d) => !matches(face(d), terrain(cell(s, p.path.at(-1)).terrain).requirement))
|
||||
.map((d) => d.id);
|
||||
return p.rerolls && ids.length ? { action: "reroll", ids } : { action: "finishRerolls" };
|
||||
}
|
||||
case "equipment":
|
||||
return { action: "ready" };
|
||||
case "movement":
|
||||
return s.activeResolution === null
|
||||
? { action: "beginMovement" }
|
||||
: s.activeResolution === seat
|
||||
? { action: "resolve" }
|
||||
: { action: "bar" };
|
||||
case "eruption":
|
||||
return { action: "erupt" };
|
||||
default:
|
||||
throw Error("Unexpected phase");
|
||||
}
|
||||
}
|
||||
let moves = 0,
|
||||
wins = 0;
|
||||
for (let players = 2; players <= 4; players++)
|
||||
for (let seed = 0; seed < 50; seed++) {
|
||||
let s = initGame(players, { difficulty: 1 + (seed % 4) }, `simulation-${seed}`);
|
||||
let steps = 0;
|
||||
while (!s.outcome && steps < 1000) {
|
||||
const active = activePlayers(s).filter(
|
||||
(i) => !["planning", "equipment"].includes(s.phase) || !s.players[i].ready
|
||||
);
|
||||
assert(active.length, "Active game must offer an action");
|
||||
const seat = active[0];
|
||||
s = applyMove(s, choose(s, seat), seat);
|
||||
assert.equal(
|
||||
new Set(s.players.flatMap((p) => p.dice.map((d) => d.id))).size,
|
||||
s.players.reduce((n, p) => n + p.dice.length, 0)
|
||||
);
|
||||
assert(s.players.every((p) => p.stamina >= 0 && p.stamina <= 25));
|
||||
steps++;
|
||||
}
|
||||
assert(s.outcome, `Deadlock: ${players}/${seed}`);
|
||||
assert.deepEqual(replay(s), s);
|
||||
moves += steps;
|
||||
if (s.outcome === "won") wins++;
|
||||
}
|
||||
console.log(`150 complete expeditions; ${moves} moves; ${wins} wins; no deadlocks; exact replays.`);
|
||||
62
tests/bgs-bundle-smoke.mjs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import { chromium } from "playwright";
|
||||
import path from "node:path";
|
||||
(async () => {
|
||||
const root = process.cwd();
|
||||
const { initGame, applyMove, stripSecret, SKILLS } = await import(root + "/packages/engine/dist/index.js");
|
||||
const game = initGame(3, {}, "bridge-test");
|
||||
const view = stripSecret(game, 0);
|
||||
const browser = await chromium.launch({ headless: true, executablePath: process.env.FUJI_CHROMIUM_EXECUTABLE });
|
||||
const page = await browser.newPage();
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.setContent('<html><head></head><body><div id="app"></div></body></html>');
|
||||
await page.addStyleTag({ path: root + "/packages/viewer/dist/fuji-viewer.css" });
|
||||
await page.addScriptTag({ path: root + "/packages/viewer/dist/fuji-viewer.iife.js" });
|
||||
await page.evaluate((view) => {
|
||||
window.captured = [];
|
||||
window.bridge = window.fuji.launch("#app");
|
||||
for (const name of ["ready", "move", "fetchState", "replaceLog"])
|
||||
window.bridge.on(name, (payload) => window.captured.push({ name, payload }));
|
||||
window.bridge.emit("player", { index: 0 });
|
||||
window.bridge.emit("state", view);
|
||||
}, view);
|
||||
await page.getByRole("button", { name: "Ready for the journey" }).click();
|
||||
await page.evaluate(() => {
|
||||
window.bridge.emit("state:updated");
|
||||
window.bridge.emit("gamelog", { start: 0, data: { log: [] } });
|
||||
});
|
||||
let captured = await page.evaluate(() => window.captured);
|
||||
const move = captured.find((e) => e.name === "move")?.payload;
|
||||
if (move?.action !== "setup" || "move" in move) throw Error("Wrong move contract");
|
||||
if (captured.filter((e) => e.name === "ready").length !== 1) throw Error("Wrong readiness handshake");
|
||||
if (captured.filter((e) => e.name === "fetchState").length !== 2) throw Error("Updates must request state");
|
||||
if (await page.locator(".dev-toolbar").count()) throw Error("Local harness leaked into bundle");
|
||||
let s = game;
|
||||
for (let i = 0; i < 3; i++)
|
||||
s = applyMove(
|
||||
s,
|
||||
{ action: "setup", keep: s.players[i].cards.slice(0, SKILLS[s.players[i].skill].keep).map((c) => c.id) },
|
||||
i
|
||||
);
|
||||
s.players[1].radio = true;
|
||||
await page.evaluate((v) => window.bridge.emit("state", v), stripSecret(s, 0));
|
||||
await page.waitForSelector(".revealed-team");
|
||||
if ((await page.locator(".revealed-team .die:not(.hidden)").count()) !== 6) throw Error("Radio not rendered");
|
||||
await page.evaluate((v) => {
|
||||
window.bridge.emit("player", {});
|
||||
window.bridge.emit("state", v);
|
||||
}, stripSecret(s));
|
||||
if (await page.locator(".personal .die").count()) throw Error("Spectator has personal dice");
|
||||
console.log(
|
||||
JSON.stringify({
|
||||
errors,
|
||||
ready: captured.filter((e) => e.name === "ready").length,
|
||||
fetchState: captured.filter((e) => e.name === "fetchState").length,
|
||||
move,
|
||||
radioVisible: true,
|
||||
localHarnessAbsent: true,
|
||||
})
|
||||
);
|
||||
if (errors.length) throw Error("Runtime errors");
|
||||
await browser.close();
|
||||
})();
|
||||
52
tests/browser-smoke.mjs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import { chromium } from "playwright";
|
||||
import fs from "node:fs";
|
||||
fs.mkdirSync("work/browser", { recursive: true });
|
||||
|
||||
(async () => {
|
||||
const browser = await chromium.launch({ headless: true, executablePath: process.env.FUJI_CHROMIUM_EXECUTABLE });
|
||||
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.goto("http://127.0.0.1:5187");
|
||||
await page.waitForSelector(".map");
|
||||
await page.getByRole("button", { name: "Ready for the journey" }).click();
|
||||
const step = page.getByRole("button", { name: "Play next teammate action" });
|
||||
await step.click();
|
||||
await step.click();
|
||||
const state = () => page.evaluate(() => JSON.parse(localStorage.getItem("fuji-dev-v1")));
|
||||
let s = await state();
|
||||
if (s.phase !== "planning") throw Error("Setup did not finish");
|
||||
await page.locator(".location.reachable").nth(1).click();
|
||||
await page.getByRole("button", { name: "Set this route" }).click();
|
||||
await page.screenshot({ path: "work/browser/fuji-planning.png", fullPage: true });
|
||||
await page.getByRole("button", { name: "Open playing guide" }).click();
|
||||
await page.keyboard.press("Escape");
|
||||
if (await page.getByRole("dialog").count()) throw Error("Escape did not close guide");
|
||||
await page.setViewportSize({ width: 390, height: 844 });
|
||||
await page.screenshot({ path: "work/browser/fuji-mobile.png", fullPage: true });
|
||||
const overflow = await page.evaluate(() => document.documentElement.scrollWidth > innerWidth);
|
||||
if (overflow) throw Error("Page overflows on mobile");
|
||||
await page.setViewportSize({ width: 1440, height: 1000 });
|
||||
let count = 0;
|
||||
const phases = new Set();
|
||||
while (!(s = await state()).outcome && count < 450) {
|
||||
phases.add(s.phase);
|
||||
await step.click();
|
||||
count++;
|
||||
if (await page.locator(".error").count()) throw Error(await page.locator(".error").innerText());
|
||||
}
|
||||
console.log(
|
||||
JSON.stringify({
|
||||
errors,
|
||||
steps: count,
|
||||
phases: [...phases],
|
||||
outcome: s.outcome,
|
||||
round: s.round,
|
||||
reason: s.reason,
|
||||
mobileOverflow: overflow,
|
||||
})
|
||||
);
|
||||
if (errors.length || !s.outcome) throw Error("Playtest incomplete");
|
||||
await page.screenshot({ path: "work/browser/fuji-result.png", fullPage: true });
|
||||
await browser.close();
|
||||
})();
|
||||