Compare commits

..

No commits in common. "main" and "master" have entirely different histories.
main ... master

42 changed files with 326 additions and 2147 deletions

BIN
.DS_Store vendored

Binary file not shown.

26
.gitignore vendored
View File

@ -1,26 +0,0 @@
# ---> Java
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*

232
LICENSE
View File

@ -1,232 +0,0 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright © 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 General Public License is a free, copyleft license for software and other kinds of works.
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is 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. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.
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.
To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.
Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.
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 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. Use with the GNU Affero General Public License.
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 Affero 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 special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of the GNU 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 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 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 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.
OOP_2B1_Project
Copyright (C) 2025 romain.murphy
This program is free software: you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details.
You should have received a copy of the GNU 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 the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:
OOP_2B1_Project Copyright (C) 2025 romain.murphy
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”.
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 GPL, see <https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read <https://www.gnu.org/philosophy/why-not-lgpl.html>.

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-23">
<attributes>
<attribute name="module" value="true"/>
</attributes>

View File

@ -14,15 +14,4 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1744449596284</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>

View File

@ -1,11 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.targetPlatform=23
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.compliance=23
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.compiler.source=23

View File

@ -1,9 +0,0 @@
BR,BN,BB,BQ,BK,BB,BN,BR
BP,BP, , , ,BP,BP,BP
WB, , , , , , ,
, , , , , , ,
, , , , , , ,
, , , ,BP, , ,WN
WP,WP,WP, , ,WP,WP,WP
WR,WN,WB,WQ,WK, , ,WR
6W

View File

@ -1,9 +0,0 @@
BR,BN,BB,BQ,BK,BB,BN,BR
BP,BP,BP, , , ,BP,BP
WB, , , ,BP,BP, ,
, , ,BP, , , ,
, , , ,WP, , ,
, , , , , , ,WN
WP,WP,WP,WP, ,WP,WP,WP
WR,WN,WB,WQ,WK, , ,WR
3W

View File

@ -1,9 +0,0 @@
BR, , ,BK, ,BR, ,
BP,WP,BP, , ,BP,BP,BP
, , , ,WP, , ,
, , , , , , ,
, , , , , , ,
, , , , , , ,
WP,WP,WP, , ,WP,WP,WP
WR,WN,WB,WQ,WK,WB,WN,WR
3W

View File

@ -1,9 +0,0 @@
, ,BB,BQ,BK, , ,BR
BP,WP,BP,BP, ,BP,BP,BP
, ,BN,BB, ,BP, ,
, , , , , , ,
, , , , , , ,
, , , , , , ,
, , , , , , ,
, , ,WK, , , ,
3W

View File

@ -1,9 +1,9 @@
BR,BN,BB,BQ,BK,BB,BN,BR
,BP,BP,BP,BP,BP,BP,BP
, , , , , , ,
BP, , ,WP, , , ,
BP,BP,BP,BP,BP,BP,BP,BP
, , , , , , ,
, , , , , , ,
WP,WP,WP, ,WP,WP,WP,WP
, , , , , , ,
, , , , , , ,
WP,WP,WP,WP,WP,WP,WP,WP
WR,WN,WB,WQ,WK,WB,WN,WR
4B
W

View File

Before

Width:  |  Height:  |  Size: 954 B

After

Width:  |  Height:  |  Size: 954 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

Binary file not shown.

View File

@ -10,13 +10,12 @@ public class Main {
public static void main(String[] args) {
// testing :
// Board testBoard = new Board(8, 8);
// testBoard.populateBoard();
// System.out.println(testBoard.toString());
Board testBoard = new Board(8, 8);
testBoard.populateBoard();
System.out.println(testBoard.toString());
// launches graphical interface :
MyInterface mjf = new MyInterface();
// mjf.introduction();
mjf.setVisible(true);
}

View File

@ -1,238 +1,17 @@
package backend;
import java.util.ArrayList;
public class AutoPlayer {
private PieceCreation pc = new PieceCreation();
private KingCheck kingCheck = new KingCheck();
public int MAX_DEPTH;
public AutoPlayer() {}
public AutoPlayer(int MAX_DEPTH) {
this.MAX_DEPTH = MAX_DEPTH;
}
private int[][] PAWN_TABLE = {
{ 0, 0, 0, 0, 0, 0, 0, 0 },
{ 5, 5, 5, -5, -5, 5, 5, 5 },
{ 1, 1, 2, 3, 3, 2, 1, 1 },
{ 0, 0, 0, 2, 2, 0, 0, 0 },
{ 1, 1, 1, 0, 0, 1, 1, 1 },
{ 2, 2, 2, -2, -2, 2, 2, 2 },
{ 5, 5, 5, 5, 5, 5, 5, 5 },
{ 0, 0, 0, 0, 0, 0, 0, 0 }
};
private int[][] KNIGHT_TABLE = {
{-50,-40,-30,-30,-30,-30,-40,-50},
{-40,-20, 0, 0, 0, 0,-20,-40},
{-30, 0, 10, 15, 15, 10, 0,-30},
{-30, 5, 15, 20, 20, 15, 5,-30},
{-30, 0, 15, 20, 20, 15, 0,-30},
{-30, 5, 10, 15, 15, 10, 5,-30},
{-40,-20, 0, 5, 5, 0,-20,-40},
{-50,-40,-30,-30,-30,-30,-40,-50}
};
private int[][] BISHOP_TABLE = {
{-20,-10,-10,-10,-10,-10,-10,-20},
{-10, 5, 0, 0, 0, 0, 5,-10},
{-10, 10, 10, 10, 10, 10, 10,-10},
{-10, 0, 10, 10, 10, 10, 0,-10},
{-10, 5, 5, 10, 10, 5, 5,-10},
{-10, 0, 5, 10, 10, 5, 0,-10},
{-10, 0, 0, 0, 0, 0, 0,-10},
{-20,-10,-10,-10,-10,-10,-10,-20}
};
private int[][] ROOK_TABLE = {
{ 0, 0, 0, 5, 5, 0, 0, 0 },
{ -5, 0, 0, 0, 0, 0, 0, -5 },
{ -5, 0, 0, 0, 0, 0, 0, -5 },
{ -5, 0, 0, 0, 0, 0, 0, -5 },
{ -5, 0, 0, 0, 0, 0, 0, -5 },
{ -5, 0, 0, 0, 0, 0, 0, -5 },
{ 5, 10, 10, 10, 10, 10, 10, 5 },
{ 0, 0, 0, 0, 0, 0, 0, 0 }
};
private int[][] QUEEN_TABLE = {
{-20,-10,-10, -5, -5,-10,-10,-20},
{-10, 0, 0, 0, 0, 0, 0,-10},
{-10, 0, 5, 5, 5, 5, 0,-10},
{ -5, 0, 5, 5, 5, 5, 0, -5},
{ 0, 0, 5, 5, 5, 5, 0, -5},
{-10, 5, 5, 5, 5, 5, 0,-10},
{-10, 0, 5, 0, 0, 0, 0,-10},
{-20,-10,-10, -5, -5,-10,-10,-20}
};
private int[][] KING_TABLE = {
{-30,-40,-40,-50,-50,-40,-40,-30},
{-30,-40,-40,-50,-50,-40,-40,-30},
{-30,-40,-40,-50,-50,-40,-40,-30},
{-30,-40,-40,-50,-50,-40,-40,-30},
{-20,-30,-30,-40,-40,-30,-30,-20},
{-10,-20,-20,-20,-20,-20,-20,-10},
{ 20, 20, 0, 0, 0, 0, 20, 20},
{ 20, 30, 10, 0, 0, 10, 30, 20}
};
public Move computeBestMove(ArrayList<ArrayList<Piece>> board, boolean isWhiteTurn, Move lastMove) {
// System.out.println(MAX_DEPTH);
Move bestMove = null;
int bestScore = isWhiteTurn ? Integer.MIN_VALUE : Integer.MAX_VALUE;
ArrayList<Move> allMoves = getAllLegalMoves(board, isWhiteTurn, lastMove);
for (Move move : allMoves) {
ArrayList<ArrayList<Piece>> simulatedBoard = simulateMove(board, move);
int score = minimax(simulatedBoard, MAX_DEPTH - 1, !isWhiteTurn, lastMove);
/**
* returns the best Move to try on provided board for active player
* @param board
* @return
*/
public Move computeBestMove(Board board) {
if (isWhiteTurn && score > bestScore) {
bestScore = score;
bestMove = move;
} else if (!isWhiteTurn && score < bestScore) {
bestScore = score;
bestMove = move;
}
}
return bestMove;
}
private int minimax(ArrayList<ArrayList<Piece>> board, int depth, boolean isWhiteTurn, Move lastMove) {
if (depth == 0) {
return evaluateBoard(board);
}
ArrayList<Move> allMoves = getAllLegalMoves(board, isWhiteTurn, lastMove);
if (allMoves.isEmpty()) return evaluateBoard(board); // checkmate or stalemate
int bestScore = isWhiteTurn ? Integer.MIN_VALUE : Integer.MAX_VALUE;
for (Move move : allMoves) {
ArrayList<ArrayList<Piece>> simulatedBoard = simulateMove(board, move);
int score = minimax(simulatedBoard, depth - 1, !isWhiteTurn, lastMove);
if (isWhiteTurn) {
bestScore = Math.max(bestScore, score);
} else {
bestScore = Math.min(bestScore, score);
}
}
return bestScore;
}
private int evaluateBoard(ArrayList<ArrayList<Piece>> board) {
int score = 0;
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 8; x++) {
Piece p = board.get(y).get(x);
if (p != null) {
int value = getPieceValue(p.getType());
int positionalBonus = getPositionalBonus(p, x, y);
if (p.isWhite()) {
score += value + positionalBonus;
} else {
score -= value + positionalBonus; // subtract opponent's bonus too
}
}
}
}
return score;
}
private int getPieceValue(PieceType type) {
switch (type) {
case Pawn:
return 10;
case Knight:
return 30;
case Bishop:
return 30;
case Rook:
return 50;
case Queen:
return 90;
case King:
return 900;
default:
return 0;
}
}
private ArrayList<ArrayList<Piece>> simulateMove(ArrayList<ArrayList<Piece>> board, Move move) {
ArrayList<ArrayList<Piece>> newBoard = deepCopyBoard(board);
Piece piece = newBoard.get(move.fromY).get(move.fromX);
newBoard.get(move.fromY).set(move.fromX, null);
piece.x = move.toX;
piece.y = move.toY;
newBoard.get(move.toY).set(move.toX, piece);
return newBoard;
}
private ArrayList<ArrayList<Piece>> deepCopyBoard(ArrayList<ArrayList<Piece>> original) {
ArrayList<ArrayList<Piece>> copy = new ArrayList<>();
for (ArrayList<Piece> row : original) {
ArrayList<Piece> newRow = new ArrayList<>();
for (Piece p : row) {
if (p != null) {
newRow.add(pc.createPiece(p.getX(), p.getY(), p.getType(), p.isWhite()));
} else {
newRow.add(null);
}
}
copy.add(newRow);
}
return copy;
}
public ArrayList<Move> getAllLegalMoves(ArrayList<ArrayList<Piece>> board, boolean isWhiteTurn, Move lastMove) {
ArrayList<Move> legalMoves = new ArrayList<>();
ArrayList<ArrayList<Boolean>> moves;
for (ArrayList<Piece> row : board) {
for (Piece p : row) {
if (p != null && p.isWhite() == isWhiteTurn) {
if (p.getType() == PieceType.King && p.getX() == 4 && (p.getY() == 0 || p.getY() == 7)) {
moves = kingCheck.checkCastling(p, board,lastMove, isWhiteTurn);
} else {moves = kingCheck.getLegalMoves(p, board, lastMove);}
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 8; x++) {
if (moves.get(y).get(x)) {
legalMoves.add(new Move(p.getX(), p.getY(), x, y));
}
}
}
}
}
}
return legalMoves;
}
private int getPositionalBonus(Piece piece, int x, int y) {
if (!piece.isWhite()) {
y = 7 - y; // mirror for black
}
switch (piece.getType()) {
case Pawn:
return PAWN_TABLE[y][x];
case Knight:
return KNIGHT_TABLE[y][x];
case Bishop:
return BISHOP_TABLE[y][x];
case Rook:
return ROOK_TABLE[y][x];
case Queen:
return QUEEN_TABLE[y][x];
case King:
return KING_TABLE[y][x];
default:
return 0;
}
}
public void setMAX_DEPTH(int mAX_DEPTH) {
MAX_DEPTH = mAX_DEPTH;
return null;
}
}

View File

@ -1,59 +0,0 @@
package backend;
import java.util.ArrayList;
public class Bishop extends Piece {
public Bishop(int x, int y, boolean isWhite) {
super(x, y, PieceType.Bishop, isWhite);
}
@Override
public ArrayList<ArrayList<Boolean>> getPossibleMoves(ArrayList<ArrayList<Piece>> board) {
// Delegate to the full method with null lastMove
return getPossibleMoves(board, null);
}
public ArrayList<ArrayList<Boolean>> getPossibleMoves(ArrayList<ArrayList<Piece>> board, Move lastMove) {
ArrayList<ArrayList<Boolean>> moves = new ArrayList<>();;
// Initialize 8x8 move grid with false
for (int i = 0; i < 8; i++) {
ArrayList<Boolean> row = new ArrayList<>();
for (int j = 0; j < 8; j++) {
row.add(false);
}
moves.add(row);
}
// Diagonal directions: top-left, top-right, bottom-left, bottom-right
int[][] directions = {
{-1, -1},
{-1, 1},
{1, -1},
{1, 1}
};
for (int[] dir : directions) {
int newY = y + dir[0];
int newX = x + dir[1];
while (newX >= 0 && newX < 8 && newY >= 0 && newY < 8) {
Piece target = board.get(newY).get(newX);
if (target == null) {
moves.get(newY).set(newX, true); // Empty square
} else {
if (target.isWhite() != this.isWhite) {
moves.get(newY).set(newX, true); // Capture opponent
}
break; // Blocked by any piece
}
newY += dir[0];
newX += dir[1];
}
}
return moves;
}
}

View File

@ -1,46 +1,31 @@
package backend;
import java.util.ArrayList;
import java.util.LinkedList;
import javax.swing.JOptionPane;
public class Board {
private PieceCreation pc = new PieceCreation();
private KingCheck kingCheck = new KingCheck();
private SoundEffect soundEffect = new SoundEffect();
private int width = 8;
private int height = 8;
private ArrayList<ArrayList<Piece>> board = new ArrayList<>();
private boolean select = false;
private int xm;
private int ym;
private int turnNumber;
private boolean turnColor;
private Move lastMove; // new field
private ArrayList<ArrayList<Boolean>> possibleMoves = new ArrayList<>();
private LinkedList<BoardHistory> boardHistory = new LinkedList<>();
public boolean timerSwitch = false;
public boolean timerStart = true;
public int width;
public int height;
public ArrayList<ArrayList<Piece>> board = new ArrayList<>();
public boolean select = false;
public int xm;
public int ym;
public int turnNumber;
public boolean turnColor;
public Board(int colNum, int lineNum) {
this.width = colNum;
this.height = lineNum;
int rows = 8;
int cols = 8;
for (int i = 0; i < rows; i++) {
ArrayList<Piece> row = new ArrayList<>();
ArrayList<Boolean> rowB = new ArrayList<>();
for (int j = 0; j < cols; j++) {
row.add(null); // Fill with null
rowB.add(false);
}
this.board.add(row);
this.possibleMoves.add(rowB);
}
this.turnNumber = 0;
this.turnColor = true;
boardHistory.add(new BoardHistory(board,turnNumber,turnColor,lastMove));
int cols = 8;
for (int i = 0; i < rows; i++) {
ArrayList<Piece> row = new ArrayList<>();
for (int j = 0; j < cols; j++) {
row.add(null); // Fill with null
}
this.board.add(row);
}
this.turnNumber = 0;
this.turnColor = true;
}
public int getWidth() {
@ -60,27 +45,27 @@ public class Board {
}
public void setPiece(int x, int y, PieceType type, boolean isWhite) {
Piece piece = pc.createPiece(x,y,type,isWhite);
Piece piece = new Piece(x,y,type,isWhite);
board.get(y).set(x, piece);
}
public void populateBoard() {//populates the board
public void populateBoard() {
for (int x = 0; x < this.width;x++) {
for (int y = 0; y < this.height; y++) {
if (y ==1 || y == 6) {
if (y == 1) {
this.setPiece(x,y,PieceType.Pawn,false);//Place the pawns
this.setPiece(x,y,PieceType.Pawn,false);
}
else if (y == 6) {this.setPiece(x,y,PieceType.Pawn,true);}
}
if (y == 0) {
boolean col = false;
if (x == 0 || x == 7) {
this.setPiece(x,y,PieceType.Rook,col);//Places the rooks
} else if (x == 1 || x == 6) {this.setPiece(x,y,PieceType.Knight,col);}// Place the Knights
else if (x == 2 || x == 5) {this.setPiece(x,y,PieceType.Bishop,col);}// Place the Bishops
else if (x == 3) {this.setPiece(x,y,PieceType.Queen,col);}// Places the queen
else if (x == 4) {this.setPiece(x,y,PieceType.King,col);}// Places the King
this.setPiece(x,y,PieceType.Rook,col);
} else if (x == 1 || x == 6) {this.setPiece(x,y,PieceType.Knight,col);}
else if (x == 2 || x == 5) {this.setPiece(x,y,PieceType.Bishop,col);}
else if (x == 3) {this.setPiece(x,y,PieceType.Queen,col);}
else if (x == 4) {this.setPiece(x,y,PieceType.King,col);}
} else if (y == 7) {
boolean col = true;
if (x == 0 || x == 7) {
@ -97,14 +82,14 @@ public class Board {
public void cleanBoard() {
int rows = 8;
int cols = 8;
for (int x = 0; x < rows; x++) {
for (int y = 0; y < cols; y++) {
this.board.get(y).set(x, null);
for (int i = 0; i < rows; i++) {
ArrayList<Piece> row = new ArrayList<>();
for (int j = 0; j < cols; j++) {
row.add(null); // Fill with null
}
this.board.add(row);
}
this.turnNumber = 0;
this.turnColor = true;
boardHistory.clear();
}
@Override
@ -114,133 +99,39 @@ public class Board {
public ArrayList<Piece> getPieces() {
ArrayList<Piece> pieces = new ArrayList<>();
for (ArrayList<Piece> row : board) {
for (Piece piece : row) {
if (piece != null) {
pieces.add(piece);
}
}
}
return pieces;
for (ArrayList<Piece> row : board) {
for (Piece piece : row) {
if (piece != null) {
pieces.add(piece);
}
}
}
return pieces;
}
public Piece getPiece(int x, int y) {
return board.get(y).get(x);
}
public void movePiece(int x, int y) {
if (select) {
boardHistory.add(new BoardHistory(board,turnNumber,turnColor,lastMove));
Piece pieceToMove = this.board.get(this.ym).get(this.xm);
boolean isCastlingMove = pieceToMove.getType() == PieceType.King && Math.abs(x - xm) == 2;
if (pieceToMove instanceof Pawn && x != xm && board.get(y).get(x) == null) {
// En passant capture
board.get(ym).set(x, null);
lastMove = new Move(xm, ym, x, y);
}
//check for castling mode:
if (isCastlingMove) {
//kingside
if (x > xm) {
Piece rook = board.get(ym).get(7);
board.get(ym).set(5, rook);
board.get(ym).set(7, null);
if (rook != null) {
rook.x = 5;
rook.setMoved(true);
}
}
if (x < xm) {
Piece rook = board.get(ym).get(0);
board.get(ym).set(3, rook);
board.get(ym).set(0, null);
if (rook != null) {
rook.x = 3;
rook.setMoved(true);
}
}
}
if (board.get(y).get(x) != null) {
soundEffect.captureSound();
} else {
soundEffect.movingSound();
}
board.get(this.ym).set(this.xm,null);
this.setPiece(x,y,pieceToMove.getType(),pieceToMove.isWhite());
Piece movedPiece = this.getPiece(x, y);
lastMove = new Move(xm, ym, x, y);
if (movedPiece instanceof Pawn) {
int promotionRow = movedPiece.isWhite() ? 0 : 7;
if (y == promotionRow) {
Object[] choices = { "Queen", "Rook", "Bishop", "Knight" };
String selected = (String) JOptionPane.showInputDialog(
null,
"Choose a piece for promotion:",
"Pawn Promotion",
JOptionPane.PLAIN_MESSAGE,
null,
choices,
"Queen"
);
Piece promoted;
switch (selected) {
case "Rook":
promoted = new Rook(x, y, false);
break;
case "Bishop":
promoted = new Bishop(x, y, false);
break;
case "Knight":
promoted = new Knight(x, y, false);
break;
default:
promoted = new Queen(x, y, false);
}
board.get(y).set(x, promoted);
this.setPiece(x,y,promoted.getType(),pieceToMove.isWhite());
}
}
if (movedPiece != null) {
movedPiece.setMoved(true);
}
}
Piece pieceToMove = this.board.get(this.ym).get(this.xm);
this.setPiece(x,y,pieceToMove.getType(),pieceToMove.isWhite());
board.get(this.ym).set(this.xm,null);
}
public void userTouch(int x, int y) {
if ((this.select == false && board.get(y).get(x) != null && this.board.get(y).get(x).isWhite() == turnColor) || (select == true && board.get(y).get(x) != null && board.get(y).get(x).isWhite() == board.get(ym).get(xm).isWhite())) {
timerStart = false;
if (this.select == false && board.get(y).get(x) != null) {
this.xm = x;
this.ym = y;
select = true;
Piece pieceToMove = this.board.get(y).get(x);
if (pieceToMove.getType() == PieceType.King && x == 4 && (y == 0 || y == 7)) {
possibleMoves = kingCheck.checkCastling(board.get(y).get(x), board,lastMove, turnColor);
} else {possibleMoves = kingCheck.getLegalMoves(pieceToMove, board, lastMove);}
// possibleMoves = board.get(y).get(x).getPossibleMoves(board);
// possibleMoves = board.get(y).get(x).getPossibleMoves(board, lastMove);//same as kingCheck
}
else if (select == true && this.xm != x || this.ym != y){
if (isHighlighted(x,y)) {
this.movePiece(x, y);
select = false;
timerSwitch = true;
this.turnColor = !this.turnColor;
if(!this.turnColor) {
this.turnNumber += 1;
}
}
}
else {
this.movePiece(x, y);
select = false;
this.turnNumber += 1;
// System.out.println(this.toString()); // Debug
this.turnColor = !this.turnColor;
} else {
select = false;
}
}
@ -252,155 +143,38 @@ public class Board {
return S;
}
public boolean isCheck(int x, int y) {
boolean out = false;
if (board.get(y).get(x) != null) {
if (board.get(y).get(x).getType() == PieceType.King && board.get(y).get(x).isWhite == turnColor){
if (kingCheck.isKingInCheck(board,turnColor)) {
out = true;
}
}
}
return out;
}
/* saving-loading feature :*/
public String[] toFileRep() {
FileBoard boardToFile = new FileBoard(board,turnNumber,turnColor);
return boardToFile.toFile();
//TODO
return null;
}
public Board(String[] array) {
FileBoard fileToBoard = new FileBoard(array);
board = fileToBoard.getBoard();
turnNumber = fileToBoard.getTurnNumber();
turnColor = fileToBoard.isTurnColor();
boardHistory.add(new BoardHistory(board,turnNumber,turnColor,lastMove));
//TODO
}
/* The following methods require more work ! */
public boolean isHighlighted(int x, int y) {
boolean toBeReturned;
if (select) {
toBeReturned = possibleMoves.get(y).get(x);
}
else { toBeReturned = false;}
return toBeReturned;
}
public ArrayList<ArrayList<Piece>> getBoard() {
return board;
//TODO
return false;
}
public void undoLastMove() {
if (boardHistory.size()>=1) {
board = boardHistory.get(boardHistory.size() - 1).getBoard();
this.turnNumber = boardHistory.getLast().getTurnNumber();
this.turnColor = boardHistory.getLast().isTurnColor();
this.lastMove = boardHistory.getLast().getLastMove();
boardHistory.removeLast();
// System.out.println(boardHistory); // Debug
}
//TODO
}
public Board(Board board) {
//TODO
}
public void playMove(Move move) {
int xm = move.getFromX();
int ym = move.getFromY();
int x = move.getToX();
int y = move.getToY();
boardHistory.add(new BoardHistory(board,turnNumber,turnColor,lastMove));
Piece pieceToMove = this.board.get(ym).get(xm);
boolean isCastlingMove = pieceToMove.getType() == PieceType.King && Math.abs(x - xm) == 2;
lastMove = new Move(xm, ym, x, y);
//TODO
if (pieceToMove instanceof Pawn && x != xm && board.get(y).get(x) == null) {
// En passant capture
board.get(ym).set(x, null);
}
//check for castling mode:
if (isCastlingMove) {
//kingside
if (x > xm) {
Piece rook = board.get(ym).get(7);
board.get(ym).set(5, rook);
board.get(ym).set(7, null);
if (rook != null) {
rook.x = 5;
rook.setMoved(true);
}
}
if (x < xm) {
Piece rook = board.get(ym).get(0);
board.get(ym).set(3, rook);
board.get(ym).set(0, null);
if (rook != null) {
rook.x = 3;
rook.setMoved(true);
}
}
}
if (board.get(y).get(x) != null) {
soundEffect.captureSound();
} else {
soundEffect.movingSound();
}
this.setPiece(x,y,pieceToMove.getType(),pieceToMove.isWhite());
Piece movedPiece = this.getPiece(x, y);
if (movedPiece != null) {
movedPiece.setMoved(true);
}
if (movedPiece instanceof Pawn) {
int promotionRow = movedPiece.isWhite() ? 0 : 7;
if (y == promotionRow) {
// System.out.println() // Debug
this.setPiece(x,y,PieceType.Queen,pieceToMove.isWhite());
}
}
board.get(ym).set(xm,null);
this.turnColor = !this.turnColor;
if(this.turnColor) {
this.turnNumber +=1;
}
}
public void setBoard(ArrayList<ArrayList<Piece>> board) {
this.board = board;
}
public void setTurnNumber(int turnNumber) {
this.turnNumber = turnNumber;
}
public void setTurnColor(boolean turnColor) {
this.turnColor = turnColor;
}
public void setBoardHistory(LinkedList<BoardHistory> boardHistory) {
this.boardHistory = boardHistory;
}
public boolean isTurnColor() {
return turnColor;
}
public Move getLastMove() {
return lastMove;
}
public boolean isTimerSwitch() {
return timerSwitch;
}
public void setTimerSwitch(boolean timerSwitch) {
this.timerSwitch = timerSwitch;
}
public boolean getTimerStart() {
return timerStart;
}
}

View File

@ -1,51 +0,0 @@
package backend;
import java.util.ArrayList;
public class BoardHistory {
public int width;
public int height;
public ArrayList<ArrayList<Piece>> board = new ArrayList<>();
public int turnNumber;
public boolean turnColor;
public Move lastMove;
private PieceCreation pc = new PieceCreation();
public BoardHistory(ArrayList<ArrayList<Piece>> board, int turnNumber, boolean turnColor, Move lastMove) {
this.board = deepCopyBoard(board);
this.turnNumber = turnNumber;
this.turnColor = turnColor;
this.lastMove = lastMove;
}
private ArrayList<ArrayList<Piece>> deepCopyBoard(ArrayList<ArrayList<Piece>> original) {
ArrayList<ArrayList<Piece>> copy = new ArrayList<>();
for (ArrayList<Piece> row : original) {
ArrayList<Piece> newRow = new ArrayList<>();
for (Piece p : row) {
if (p != null) {
newRow.add(pc.createPiece(p.getX(), p.getY(), p.getType(), p.isWhite()));
} else {
newRow.add(null);
}
}
copy.add(newRow);
}
return copy;
}
public ArrayList<ArrayList<Piece>> getBoard() {
return board;
}
public int getTurnNumber() {
return turnNumber;
}
public boolean isTurnColor() {
return turnColor;
}
@Override
public String toString() {
return "BoardHistory [board=" + board + "]";
}
public Move getLastMove() {
return lastMove;
}
}

View File

@ -1,109 +0,0 @@
package backend;
import java.util.ArrayList;
public class FileBoard {
public ArrayList<ArrayList<Piece>> board = new ArrayList<>();
public int turnNumber;
public boolean turnColor;
private PieceCreation pc = new PieceCreation();
public FileBoard(ArrayList<ArrayList<Piece>> board,int turnNumber, boolean turnColor) {
this.board = board;
this.turnColor = turnColor;
this.turnNumber = turnNumber;
}
public String[] toFile() {
String tC;
String toBeWritten = " ";
String activeLine = "";
String[] boardFile = new String[9];
for (int y = 0;y<8;y++) {
for (int x = 0;x<8;x++) {
if (x!= 7) {
if (board.get(y).get(x) != null) {
if (board.get(y).get(x).isWhite() == true) {
toBeWritten = 'W' + board.get(y).get(x).getType().getSummary() + ",";
} else {
toBeWritten = 'B' + board.get(y).get(x).getType().getSummary() + ",";
}
} else {toBeWritten = " ,";}
activeLine += toBeWritten;
} else {
if (board.get(y).get(x) != null) {
if (board.get(y).get(x).isWhite() == true) {
toBeWritten = 'W' + board.get(y).get(x).getType().getSummary();
} else {
toBeWritten = 'B' + board.get(y).get(x).getType().getSummary();
}
} else {toBeWritten = " ";}
activeLine += toBeWritten;
}
}
boardFile[y] = activeLine;
activeLine = "";
}
if (turnColor) {
tC = "W";
} else {tC = "B";}
boardFile[8] = turnNumber + tC;
return boardFile;
}
public FileBoard(String[] boardFile) {
ArrayList<ArrayList<Piece>> boardF = new ArrayList<>();
int rows = 8;
int cols = 8;
for (int i = 0; i < rows; i++) {
ArrayList<Piece> row = new ArrayList<>();
for (int j = 0; j < cols; j++) {
row.add(null); // Fill with null
}
boardF.add(row);
}
String pieceChar;
char color;
char type;
boolean col;
for (int x = 0; x<8;x++) {
for (int y = 0; y<8;y++) {
pieceChar = getCharAt(boardFile,x,y);
if (pieceChar.charAt(0) != ' ') {
// System.out.println(pieceChar); // Debug
color = pieceChar.charAt(0);
type = pieceChar.charAt(1);
col = color == 'W';
Piece piece = pc.createPiece(x,y,PieceType.fromSummary(type),col);
boardF.get(y).set(x, piece);
}
}
}
pieceChar = getCharAt(boardFile,0,8);
char turnNb = pieceChar.charAt(0);
char colorChar = pieceChar.charAt(1);
this.board = boardF;
this.turnColor = colorChar == 'W';
this.turnNumber = turnNb - '0';
}
public String getCharAt(String[] str,int x,int y) {
return str[y].split(",")[x];
}
public ArrayList<ArrayList<Piece>> getBoard() {
return board;
}
public int getTurnNumber() {
return turnNumber;
}
public boolean isTurnColor() {
return turnColor;
}
public void setBoard(ArrayList<ArrayList<Piece>> board) {
this.board = board;
}
public void setTurnNumber(int turnNumber) {
this.turnNumber = turnNumber;
}
public void setTurnColor(boolean turnColor) {
this.turnColor = turnColor;
}
}

View File

@ -3,15 +3,16 @@ package backend;
import windowInterface.MyInterface;
public class Game extends Thread {
private AutoPlayer aiPlayer;
private Board board;
public MyInterface mjf;
private MyInterface mjf;
private int COL_NUM = 8;
private int LINE_NUM = 8;
private int loopDelay = 250;
boolean[] activationAIFlags;
SoundEffect soundEffect = new SoundEffect();
public Game(MyInterface mjfParam) {
mjf = mjfParam;
board = new Board(COL_NUM, LINE_NUM);
@ -48,13 +49,7 @@ public class Game extends Thread {
private void aiPlayerTurn() {
if(isAITurn()) {
if (aiPlayer.getAllLegalMoves(board.getBoard(), board.isTurnWhite(), board.getLastMove()).size() == 0){
mjf.showGameOverMessage("Game Over");
}
else {
board.playMove(aiPlayer.computeBestMove(board.getBoard(),board.isTurnWhite(),board.getLastMove()));
mjf.timerManager.switchTurn();
}
board.playMove(aiPlayer.computeBestMove(new Board(board)));
}
}
@ -65,21 +60,8 @@ public class Game extends Thread {
System.out.println("Click out of bounds");
return;
}
if (board.getTimerStart()) {
mjf.startTimer(board.isTurnColor());
}
if(!isAITurn()) {
if (aiPlayer.getAllLegalMoves(board.getBoard(), board.isTurnWhite(),board.getLastMove()).size() != 0){
board.userTouch(x, y);
}
else {
mjf.showGameOverMessage("Game Over");
}
if (board.isTimerSwitch()) {
mjf.timerManager.switchTurn();
board.setTimerSwitch(false);
}
board.userTouch(x, y);
}
}
@ -109,10 +91,6 @@ public class Game extends Thread {
return board.getPieces();
}
public boolean isCheck(int x, int y) {
return board.isCheck(x, y);
}
public boolean isSelected(int x, int y) {
return board.isSelected(x, y);
}
@ -126,29 +104,7 @@ public class Game extends Thread {
}
public void toggleAI(boolean isWhite) {
// System.out.println(isWhite);
this.activationAIFlags[isWhite?1:0] = !this.activationAIFlags[isWhite?1:0];
if (this.activationAIFlags[isWhite?1:0]) {
soundEffect.aiSound();
}
}
public void setTurnNumber(int turnNumber) {
board.setTurnNumber(turnNumber);
}
public void setTurnColor(boolean turnColor) {
board.setTurnColor(turnColor);
}
public int getTurnNumber() {
return board.getTurnNumber();
}
public boolean getTurnColor() {
return board.isTurnColor();
}
public void setAutoPlayerDepth(int depth) {
aiPlayer.setMAX_DEPTH(depth);
}
}

View File

@ -1,5 +0,0 @@
package backend;
public class History {
}

View File

@ -1,73 +0,0 @@
package backend;
import java.util.ArrayList;
public class King extends Piece {
public King(int x, int y, boolean isWhite) {
super(x, y, PieceType.King, isWhite);
}
@Override
public ArrayList<ArrayList<Boolean>> getPossibleMoves(ArrayList<ArrayList<Piece>> board) {
// Delegate to the full method with null lastMove
return getPossibleMoves(board, null);
}
public ArrayList<ArrayList<Boolean>> getPossibleMoves(ArrayList<ArrayList<Piece>> board, Move lastMove) {
ArrayList<ArrayList<Boolean>> moves = new ArrayList<>();
// Initialize 8x8 move grid with false
for (int i = 0; i < 8; i++) {
ArrayList<Boolean> row = new ArrayList<>();
for (int j = 0; j < 8; j++) {
row.add(false);
}
moves.add(row);
}
// All 8 directions
int[][] directions = {
{-1, 0}, // up
{1, 0}, // down
{0, -1}, // left
{0, 1}, // right
{-1, -1}, // top-left
{-1, 1}, // top-right
{1, -1}, // bottom-left
{1, 1} // bottom-right
};
for (int[] dir : directions) {
int newY = y + dir[0];
int newX = x + dir[1];
if (newX >= 0 && newX < 8 && newY >= 0 && newY < 8) {
Piece target = board.get(newY).get(newX);
if (target == null || target.isWhite() != this.isWhite) {
moves.get(newY).set(newX, true);
}
}
}
//kingside method
if (!this.hasMoved() && x + 3 < 8) {
Piece rook = board.get(y).get(x +3);
if (rook != null && rook.getType() == PieceType.Rook && !rook.hasMoved() && rook.isWhite() == this.isWhite) {
if (board.get(y).get(x + 1) == null && board.get(y).get(x + 2) == null) {
moves.get(y).set(x + 2, true);
}
}
}
//queensside method
if (!this.hasMoved() && x - 4 >= 0) {
Piece rook = board.get(y).get(x -4);
if (rook != null && rook.getType() == PieceType.Rook && !rook.hasMoved() && rook.isWhite() == this.isWhite) {
if (board.get(y).get(x - 1) == null && board.get(y).get(x - 2) == null && board.get(y).get(x - 3) == null) {
moves.get(y).set(x - 2, true);
}
}
}
return moves;
}
}

View File

@ -1,113 +0,0 @@
package backend;
import java.util.ArrayList;
public class KingCheck {
private boolean opponentWasInCheck = false;
private SoundEffect soundEffect = new SoundEffect();
private boolean soundShouldPlay = true;
private PieceCreation pc = new PieceCreation();
public ArrayList<ArrayList<Boolean>> getLegalMoves(Piece piece, ArrayList<ArrayList<Piece>> board, Move lastMove) {
ArrayList<ArrayList<Boolean>> rawMoves = piece.getPossibleMoves(board,lastMove);
ArrayList<ArrayList<Boolean>> legalMoves = new ArrayList<>();
for (int y = 0; y < 8; y++) {
ArrayList<Boolean> row = new ArrayList<>();
for (int x = 0; x < 8; x++) {
row.add(false);
}
legalMoves.add(row);
}
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 8; x++) {
if (rawMoves.get(y).get(x)) {
Move move = new Move(piece.getX(), piece.getY(), x, y);
if (isMoveSafe(board, move, piece.isWhite())) {
legalMoves.get(y).set(x, true);
}
}
}
}
return legalMoves;
}
public boolean isKingInCheck(ArrayList<ArrayList<Piece>> board, boolean isWhiteTurn) {
int kingX = -1, kingY = -1;
// Find the king
for (ArrayList<Piece> row : board) {
for (Piece p : row) {
if (p != null && p.isWhite() == isWhiteTurn && p.getType() == PieceType.King) {
kingX = p.getX();
kingY = p.getY();
break;
}
}
}
if (kingX == -1 || kingY == -1) {
return true; // King not found, technically in check
}
// Check if any enemy piece can capture the king
for (ArrayList<Piece> row : board) {
for (Piece p : row) {
if (p != null && p.isWhite() != isWhiteTurn) {
ArrayList<ArrayList<Boolean>> moves = p.getPossibleMoves(board);
if (moves.get(kingY).get(kingX)) {
return true;
}
}
}
}
return false; // King is safe
}
private boolean isMoveSafe(ArrayList<ArrayList<Piece>> board, Move move, boolean isWhiteTurn) {
ArrayList<ArrayList<Piece>> simulatedBoard = simulateMove(board, move);
return !isKingInCheck(simulatedBoard, isWhiteTurn);
}
private ArrayList<ArrayList<Piece>> simulateMove(ArrayList<ArrayList<Piece>> board, Move move) {
ArrayList<ArrayList<Piece>> newBoard = deepCopyBoard(board);
Piece piece = newBoard.get(move.fromY).get(move.fromX);
newBoard.get(move.fromY).set(move.fromX, null);
piece.x = move.toX;
piece.y = move.toY;
newBoard.get(move.toY).set(move.toX, piece);
return newBoard;
}
private ArrayList<ArrayList<Piece>> deepCopyBoard(ArrayList<ArrayList<Piece>> original) {
ArrayList<ArrayList<Piece>> copy = new ArrayList<>();
for (ArrayList<Piece> row : original) {
ArrayList<Piece> newRow = new ArrayList<>();
for (Piece p : row) {
if (p != null) {
newRow.add(pc.createPiece(p.getX(), p.getY(), p.getType(), p.isWhite()));
} else {
newRow.add(null);
}
}
copy.add(newRow);
}
return copy;
}
public ArrayList<ArrayList<Boolean>> checkCastling(Piece piece, ArrayList<ArrayList<Piece>> board, Move lastMove, boolean isWhiteTurn) {
ArrayList<ArrayList<Boolean>> possibleMoves = getLegalMoves(piece, board, lastMove);
if (isKingInCheck(board,isWhiteTurn)) {
int x = piece.getX();
int y = piece.getY();
possibleMoves.get(y).set(x+2,false);
possibleMoves.get(y).set(x-2,false);
}
return possibleMoves;
}
}

View File

@ -1,52 +0,0 @@
package backend;
import java.util.ArrayList;
public class Knight extends Piece {
public Knight(int x, int y, boolean isWhite) {
super(x, y, PieceType.Knight, isWhite);
}
@Override
public ArrayList<ArrayList<Boolean>> getPossibleMoves(ArrayList<ArrayList<Piece>> board) {
// Delegate to the full method with null lastMove
return getPossibleMoves(board, null);
}
public ArrayList<ArrayList<Boolean>> getPossibleMoves(ArrayList<ArrayList<Piece>> board, Move lastMove) {
ArrayList<ArrayList<Boolean>> moves = new ArrayList<>();
// Initialize empty move grid
for (int i = 0; i < 8; i++) {
ArrayList<Boolean> row = new ArrayList<>();
for (int j = 0; j < 8; j++) {
row.add(false);
}
moves.add(row);
}
// L-shaped moves: (±2, ±1) and (±1, ±2)
int[][] deltas = {
{-2, -1}, {-2, 1},
{-1, -2}, {-1, 2},
{1, -2}, {1, 2},
{2, -1}, {2, 1}
};
for (int[] delta : deltas) {
int newY = y + delta[0];
int newX = x + delta[1];
if (newX >= 0 && newX < 8 && newY >= 0 && newY < 8) {
Piece target = board.get(newY).get(newX);
if (target == null || target.isWhite() != this.isWhite) {
moves.get(newY).set(newX, true); // Empty or opponent
}
}
}
return moves;
}
}

View File

@ -1,35 +1,5 @@
package backend;
public class Move {
public int fromX, fromY, toX, toY;
public Move(int fromX, int fromY, int toX, int toY) {
this.fromX = fromX;
this.fromY = fromY;
this.toX = toX;
this.toY = toY;
}
public int getFromX() {
return fromX;
}
public int getFromY() {
return fromY;
}
public int getToX() {
return toX;
}
public int getToY() {
return toY;
}
@Override
public String toString() {
return "(" + fromX + "," + fromY + ") → (" + toX + "," + toY + ")";
}
}
////

View File

@ -1,85 +0,0 @@
package backend;
import java.util.ArrayList;
public class Pawn extends Piece {
public Pawn(int x, int y, boolean isWhite) {
super(x, y, PieceType.Pawn, isWhite);
}
@Override
public ArrayList<ArrayList<Boolean>> getPossibleMoves(ArrayList<ArrayList<Piece>> board) {
// Delegate to the full method with null lastMove
return getPossibleMoves(board, null);
}
@Override
public ArrayList<ArrayList<Boolean>> getPossibleMoves(ArrayList<ArrayList<Piece>> board, Move lastMove) {
ArrayList<ArrayList<Boolean>> moves = new ArrayList<>();
for (int i = 0; i < 8; i++) {
ArrayList<Boolean> row = new ArrayList<>();
for (int j = 0; j < 8; j++) {
row.add(false);
}
moves.add(row);
}
int direction = isWhite ? -1 : 1;
int startRow = isWhite ? 6 : 1;
// Move forward
int nextY = y + direction;
if (isValid(nextY, x) && board.get(nextY).get(x) == null) {
moves.get(nextY).set(x, true);
// Two steps forward
int doubleY = y + 2 * direction;
if (y == startRow && board.get(doubleY).get(x) == null) {
moves.get(doubleY).set(x, true);
}
}
// Captures
for (int dx : new int[]{-1, 1}) {
int newX = x + dx;
if (isValid(nextY, newX)) {
Piece target = board.get(nextY).get(newX);
if (target != null && target.isWhite() != this.isWhite) {
moves.get(nextY).set(newX, true);
}
}
}
// En Passant mode
if (lastMove != null && lastMove.getToY() != lastMove.getFromY()) {
if (Math.abs(lastMove.getToY() - lastMove.getFromY()) == 2) {
for (int dx : new int[]{-1, 1}) {
int newX = x + dx;
if (isValid(y, newX)) {
Piece adjacent = board.get(y).get(newX);
if (adjacent instanceof Pawn && adjacent.isWhite() != this.isWhite) {
if (lastMove.getToX() == newX && lastMove.getToY() == y) {
int enPassantY = y + direction;
if (isValid(enPassantY, newX)) {
moves.get(enPassantY).set(newX, true);
}
}
}
}
}
}
}
return moves;
}
//on est bien dans les bornes !
private boolean isValid(int row, int col) {
return row >= 0 && row < 8 && col >= 0 && col < 8;
}
}
////

View File

@ -1,74 +1,35 @@
package backend;
import java.util.ArrayList;
public class Piece {
public int x;
public int y;
public PieceType type;
public boolean isWhite;
public abstract class Piece {
public int x;
public int y;
public PieceType type;
public boolean isWhite;
public Piece(int x, int y, PieceType type, boolean isWhite) {
this.x = x;
this.y = y;
this.type = type;
this.isWhite = isWhite;
}
public int getX() {
return this.x;
}
public int getY() {
return this.y;
}
protected int previousY;
public PieceType getType() {
return this.type;
}
private boolean hasMoved = false;
public boolean isWhite() {
return this.isWhite;
}
@Override
public String toString() {
return "Piece [x=" + x + ", y=" + y + ", type=" + type + ", isWhite=" + isWhite + "]";
}
public Piece(int x, int y, PieceType type, boolean isWhite) {
this.x = x;
this.y = y;
this.type = type;
this.isWhite = isWhite;
this.previousY = y;
}
public int getX() {
return this.x;
}
public int getY() {
return this.y;
}
public PieceType getType() {
return this.type;
}
public boolean isWhite() {
return this.isWhite;
}
public int getPreviousY() {
return previousY;
}
public void moveTo(int newX, int newY) {
this.previousY = this.y;
this.x = newX;
this.y = newY;
this.hasMoved = true;
}
public boolean hasMoved() {
return hasMoved;
}
public void setMoved(boolean moved) {
this.hasMoved = moved;
}
public abstract ArrayList<ArrayList<Boolean>> getPossibleMoves(ArrayList<ArrayList<Piece>> board);
@Override
public String toString() {
return "Piece [x=" + x + ", y=" + y + ", type=" + type + ", isWhite=" + isWhite + "]";
}
public ArrayList<ArrayList<Boolean>> getPossibleMoves(ArrayList<ArrayList<Piece>> board, Move lastMove) {
return null;
}
}

View File

@ -1,15 +0,0 @@
package backend;
public class PieceCreation {
public Piece createPiece(int x, int y, PieceType type, boolean isWhite) {
switch (type) {
case Pawn: return new Pawn(x, y, isWhite);
case Rook: return new Rook(x, y, isWhite);
case Knight: return new Knight(x, y, isWhite);
case Bishop: return new Bishop(x, y, isWhite);
case Queen: return new Queen(x, y, isWhite);
case King: return new King(x, y, isWhite);
default: throw new IllegalArgumentException("Unknown piece type: " + type);
}
}
}

View File

@ -0,0 +1,47 @@
package backend;
import java.util.ArrayList;
public class PossibleMovements {
ArrayList<ArrayList<Piece>> board;
Piece pieceToMove;
PieceType type;
int x;
int y;
boolean turnColor;
public PossibleMovements(ArrayList<ArrayList<Piece>> board, int x, int y,boolean turnColor) {
this.board = board;
this.pieceToMove = board.get(y).get(x);
this.type = pieceToMove.getType();
this.x = x;
this.y = y;
this.turnColor = turnColor;
}
public ArrayList<ArrayList<Boolean>> PM(){
ArrayList<ArrayList<Boolean>> possibleMoves = new ArrayList<>();
int rows = 8;
int cols = 8;
for (int i = 0; i < rows; i++) {
ArrayList<Boolean> row = new ArrayList<>();
for (int j = 0; j < cols; j++) {
row.add(false); // Fill with false
}
possibleMoves.add(row);
}
if (turnColor) {
if (type == PieceType.Pawn) {
if (x == 0) {
if (board.get(y).get(x+1) != null) {
possibleMoves.get(y).set(x+1, true);
}
}
if (x==7) {
if (board.get(y).get(x-1) != null) {
possibleMoves.get(y).set(x-1, true);
}
}
for (int xi = 1; xi<7;i++) {
}
}
}
}

View File

@ -1,63 +0,0 @@
package backend;
import java.util.ArrayList;
public class Queen extends Piece {
public Queen(int x, int y, boolean isWhite) {
super(x, y, PieceType.Queen, isWhite);
}
@Override
public ArrayList<ArrayList<Boolean>> getPossibleMoves(ArrayList<ArrayList<Piece>> board) {
// Delegate to the full method with null lastMove
return getPossibleMoves(board, null);
}
public ArrayList<ArrayList<Boolean>> getPossibleMoves(ArrayList<ArrayList<Piece>> board, Move lastMove) {
ArrayList<ArrayList<Boolean>> moves = new ArrayList<>();
// Initialize 8x8 move grid with false
for (int i = 0; i < 8; i++) {
ArrayList<Boolean> row = new ArrayList<>();
for (int j = 0; j < 8; j++) {
row.add(false);
}
moves.add(row);
}
// Queen directions: Rook + Bishop
int[][] directions = {
{-1, 0}, // up
{1, 0}, // down
{0, -1}, // left
{0, 1}, // right
{-1, -1}, // top-left
{-1, 1}, // top-right
{1, -1}, // bottom-left
{1, 1} // bottom-right
};
for (int[] dir : directions) {
int newY = y + dir[0];
int newX = x + dir[1];
while (newX >= 0 && newX < 8 && newY >= 0 && newY < 8) {
Piece target = board.get(newY).get(newX);
if (target == null) {
moves.get(newY).set(newX, true);
} else {
if (target.isWhite() != this.isWhite) {
moves.get(newY).set(newX, true); // Can capture
}
break; // Blocked
}
newY += dir[0];
newX += dir[1];
}
}
return moves;
}
}

View File

@ -1,59 +0,0 @@
package backend;
import java.util.ArrayList;
public class Rook extends Piece {
public Rook(int x, int y, boolean isWhite) {
super(x, y, PieceType.Rook, isWhite);
}
@Override
public ArrayList<ArrayList<Boolean>> getPossibleMoves(ArrayList<ArrayList<Piece>> board) {
// Delegate to the full method with null lastMove
return getPossibleMoves(board, null);
}
public ArrayList<ArrayList<Boolean>> getPossibleMoves(ArrayList<ArrayList<Piece>> board, Move lastMove) {
ArrayList<ArrayList<Boolean>> moves = new ArrayList<>();
// Initialize empty move grid
for (int i = 0; i < 8; i++) {
ArrayList<Boolean> row = new ArrayList<>();
for (int j = 0; j < 8; j++) {
row.add(false);
}
moves.add(row);
}
// Directions: up, down, left, right
int[][] directions = {
{-1, 0}, // up
{1, 0}, // down
{0, -1}, // left
{0, 1} // right
};
for (int[] dir : directions) {
int newY = y + dir[0];
int newX = x + dir[1];
while (newX >= 0 && newX < 8 && newY >= 0 && newY < 8) {
Piece target = board.get(newY).get(newX);
if (target == null) {
moves.get(newY).set(newX, true); // Empty square
} else {
if (target.isWhite() != this.isWhite) {
moves.get(newY).set(newX, true); // Capture opponent
}
break; // Stop at the first piece (can't jump)
}
newY += dir[0];
newX += dir[1];
}
}
return moves;
}
}

View File

@ -1,43 +0,0 @@
package backend;
import javax.sound.sampled.*;
import java.io.File;
import java.io.IOException;
public class SoundEffect {
public void captureSound() {
try {
File file = new File("sounds/capture.wav");
AudioInputStream audioStream = AudioSystem.getAudioInputStream(file);
Clip clip = AudioSystem.getClip();
clip.open(audioStream);
clip.start();
} catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
e.printStackTrace();
}
}
public void movingSound() {
try {
File file = new File("sounds/move-self.wav");
AudioInputStream audioStream = AudioSystem.getAudioInputStream(file);
Clip clip = AudioSystem.getClip();
clip.open(audioStream);
clip.start();
} catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
e.printStackTrace();
}
}
public void aiSound() {
try {
File file = new File("sounds/Voicy_R2-D2-7.wav");
AudioInputStream audioStream = AudioSystem.getAudioInputStream(file);
Clip clip = AudioSystem.getClip();
clip.open(audioStream);
clip.start();
} catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
e.printStackTrace();
}
}
}

View File

@ -1,29 +0,0 @@
package backend;
public class lastMove {
private int fromX, fromY, toX, toY;
public lastMove(int fromX, int fromY, int toX, int toY) {
this.fromX = fromX;
this.fromY = fromY;
this.toX = toX;
this.toY = toY;
}
public int getFromX() {
return fromX;
}
public int getFromY() {
return fromY;
}
public int getToX() {
return toX;
}
public int getToY() {
return toY;
}
}
//

View File

@ -10,7 +10,6 @@ import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import backend.Game;
@ -23,16 +22,14 @@ public class JPanelChessBoard extends JPanel {
private Game myGame;
private MyInterface interfaceGlobal;
private BufferedImage spriteSheet;
private int PIECE_WIDTH = 200; //in spritesheet
private int PIECE_HEIGHT = 200; //in spritesheet
private int MARGIN = 0;
private int PIECE_WIDTH = 16; //in spritesheet
private int PIECE_HEIGHT = 16; //in spritesheet
private int MARGIN = 6;
private boolean pieceSelectorMode;
private boolean selectedPieceIsWhite;
private PieceType selectedPieceType;
private boolean pieceAdderMode;
private Image backgroundImage;
public JPanelChessBoard(MyInterface itf) {
super();
@ -41,10 +38,8 @@ public class JPanelChessBoard extends JPanel {
selectedPieceIsWhite = true;
selectedPieceType = PieceType.Pawn;
pieceSelectorMode = false;
backgroundImage = new ImageIcon(getClass().getResource("image_OOP.png")).getImage();
try {
spriteSheet = ImageIO.read(new File("pieces/newPieces.png"));
spriteSheet = ImageIO.read(new File("pieces.png"));
} catch (IOException e) {
e.printStackTrace();
}
@ -60,17 +55,16 @@ public class JPanelChessBoard extends JPanel {
pieceSelectorMode = false;
} else {
if(myGame == null) {
// interfaceGlobal.instantiateSimu();
interfaceGlobal.instantiateSimu();
}
else {
int x = (me.getX()*myGame.getWidth())/getWidth();
int y = (me.getY()*myGame.getHeight())/getHeight();
if(pieceAdderMode) {
myGame.setPiece(x, y, selectedPieceType, selectedPieceIsWhite);
pieceAdderMode = false;
} else {
myGame.clickCoords(x,y);
}
int x = (me.getX()*myGame.getWidth())/getWidth();
int y = (me.getY()*myGame.getHeight())/getHeight();
if(pieceAdderMode) {
//TODO
myGame.setPiece(x, y, selectedPieceType, selectedPieceIsWhite);
pieceAdderMode = false;
} else {
myGame.clickCoords(x,y);
}
}
repaint();
@ -86,8 +80,7 @@ public class JPanelChessBoard extends JPanel {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(backgroundImage, 0, 0, getWidth(), getHeight(), this);
// this.setBackground(new Color(238,236,208));
this.setBackground(Color.black);
if(pieceSelectorMode) {
g.drawImage(
spriteSheet,
@ -101,28 +94,21 @@ public class JPanelChessBoard extends JPanel {
}
if (myGame != null) {
// Draw Interface from state of simulator
g.setColor(new Color(238, 236, 208)); // Your default color
g.fillRect(0, 0, getWidth()+1, getHeight()+1);
repaint();
float cellWidth = cellWidth();
float cellHeight = cellHeight();
g.setColor(new Color(115, 149, 82));
g.setColor(Color.white);
for(int x=0; x<myGame.getWidth();x++) {
for (int y=0; y<myGame.getHeight(); y++) {
boolean isSelect = myGame.isSelected(x,y);
boolean isHighlight = myGame.isHighlighted(x,y);
boolean isCheck = myGame.isCheck(x,y);
if (isCheck) {
g.setColor(Color.red);
}
if(isSelect) {
g.setColor(Color.blue);
}
if(isHighlight) {
g.setColor(Color.yellow);
}
if((x+y)%2==1 || isSelect || isHighlight || isCheck) {
if((x+y)%2==1 || isSelect || isHighlight) {
g.fillRect(
Math.round(x*cellWidth),
Math.round(y*cellHeight),
@ -130,8 +116,8 @@ public class JPanelChessBoard extends JPanel {
Math.round(cellHeight)
);
}
if(isHighlight || isSelect || isCheck) {
g.setColor(new Color(115, 149, 82));
if(isHighlight || isSelect) {
g.setColor(Color.white);
}
}
@ -150,28 +136,12 @@ public class JPanelChessBoard extends JPanel {
for (Piece piece : myGame.getPieces()) {
drawPiece(g,piece);
}
g.setColor(Color.BLACK);
for (int x = 0; x < myGame.getWidth(); x++) {
char letter = (char) ('a' + x);
int xLetter = Math.round(x * cellWidth() + cellWidth() / 2) - 4;
int yLetter = getHeight() - 5;
g.drawString(String.valueOf(letter), xLetter, yLetter);
}
for (int y = 0; y < myGame.getHeight(); y++) {
int number = myGame.getHeight() - y;
int xNumber = 5;
int yNumber = Math.round(y * cellHeight() + cellHeight() / 2) + 5;
g.drawString(String.valueOf(number), xNumber, yNumber);
}
}
}
private void drawPiece(Graphics g, Piece piece) {
g.drawImage(
getChessPieceImageFromType(piece.getType(), !piece.isWhite()),
getChessPieceImageFromType(piece.getType(), piece.isWhite()),
MARGIN+(xCoordFromGame(piece.getX())),
MARGIN+(yCoordFromGame(piece.getY())),
null

View File

@ -1,5 +1,4 @@
package windowInterface;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
@ -26,15 +25,10 @@ import java.util.Arrays;
import java.util.LinkedList;
import java.awt.event.ActionEvent;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.AbstractListModel;
import javax.swing.ImageIcon;
import javax.swing.JToggleButton;
import javax.swing.JRadioButton;
import javax.swing.JCheckBox;
import javax.swing.*;
import java.awt.*;
public class MyInterface extends JFrame {
@ -48,23 +42,13 @@ public class MyInterface extends JFrame {
private JLabel actionLabel;
private JCheckBox chckbxBlackAI;
private JCheckBox chckbxWhiteAI;
private JLabel whiteTimerLabel;
private JLabel blackTimerLabel;
public TimerManager timerManager;
/**
* Create the frame.
*/
public MyInterface() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(10, 10, 800, 800);
setBounds(10, 10, 650, 650);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
@ -152,11 +136,6 @@ public class MyInterface extends JFrame {
panelDraw = new JPanelChessBoard(this);
contentPane.add(panelDraw, BorderLayout.CENTER);
whiteTimerLabel = new JLabel("White: X");
blackTimerLabel = new JLabel("Black: X");
panelTop.add(whiteTimerLabel);
panelTop.add(blackTimerLabel);
}
public void setStepBanner(String s) {
@ -179,17 +158,11 @@ public class MyInterface extends JFrame {
}
}
public void clicButtonStart() {
this.instantiateSimu();
int depth = askDifficulty();
int time = askTime();
game.setAutoPlayerDepth(depth);
game.setDefaultSetup();
if (timerManager == null)
timerManager = new TimerManager(whiteTimerLabel, blackTimerLabel, () -> gameOverByTimeout(), time);
timerManager.reset(time);
}
public void clickButtonAdder() {
panelDraw.toggleAdderMode();
}
@ -226,6 +199,7 @@ public class MyInterface extends JFrame {
try {
BufferedReader fileContent = new BufferedReader(new FileReader(fileName));
String line = fileContent.readLine();
int colorID = 0;
while (line != null) {
lines.add(line);
line = fileContent.readLine();
@ -236,18 +210,8 @@ public class MyInterface extends JFrame {
e.printStackTrace();
}
game = loadedSim;
panelDraw.setGame(game);
int depth = askDifficulty();
int time = askTime();
game.setAutoPlayerDepth(depth);
if (timerManager == null)
timerManager = new TimerManager(whiteTimerLabel, blackTimerLabel, () -> gameOverByTimeout(), time);
timerManager.reset(time);
// timerManager.start(game.getTurnColor());
game.start();
// this.repaint();
// update(game.getTurnNumber(), game.getTurnColor());
this.repaint();
}
}
@ -302,112 +266,4 @@ public class MyInterface extends JFrame {
this.setStepBanner("Turn : X");
}
public void showGameOverMessage(String message) {
game.toggleAI(false);
game.toggleAI(true);
chckbxWhiteAI.setSelected(false);
chckbxBlackAI.setSelected(false);
Object[] options = {"YES", "NO", "Start a new game"};
int choice = JOptionPane.showOptionDialog(this, "GAME OVER \nDo you want to exit? ",
"Game Over",
JOptionPane.DEFAULT_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[1] // default: NO
);
switch (choice) {
case 0: System.exit(0); // exit
case 1: ;
case 2: clicButtonStart();
break;
default: ;
}
}
private int askDifficulty() {
Object[] options = {"Easy", "Medium", "Hard"};
int choice = JOptionPane.showOptionDialog(
this,
"Select Difficulty Level:",
"Difficulty",
JOptionPane.DEFAULT_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[1] // default: Medium
);
switch (choice) {
case 0: return 2; // Easy
case 1: return 3; // Medium
case 2: return 4; // Hard
default: return 3; // fallback to Medium
}
}
private int askTime() {
Object[] options = {"1 min", "2 Min", "5 Min", "10 Min"};
int choice = JOptionPane.showOptionDialog(
this,
"Select the duration of the game:",
"Duration",
JOptionPane.DEFAULT_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[3] // default: 10
);
switch (choice) {
case 0: return 60; // 1 min
case 1: return 120; // 2 min
case 2: return 300; // 5 min
case 3: return 600;// 10 min
default: return 600; // 10 min
}
}
public int introduction() {
int boardWidth = 600;
int boardHeight = 600;
String imagePath = "image_OOP.png"; // replace with your actual image path
ImageIcon originalIcon = new ImageIcon(imagePath);
// Check if the image was loaded successfully
if (originalIcon.getImageLoadStatus() != MediaTracker.COMPLETE) {
JOptionPane.showMessageDialog(this, "Error loading image: " + imagePath, "Image Error", JOptionPane.ERROR_MESSAGE);
return 0; // Return or handle the error as needed
}
Image originalImage = originalIcon.getImage();
Image resizedImage = originalImage.getScaledInstance(boardWidth, boardHeight, Image.SCALE_SMOOTH);
ImageIcon resizedIcon = new ImageIcon(resizedImage);
Object[] options = {"Start"};
int choice = JOptionPane.showOptionDialog(
this,
" ",
" ",
JOptionPane.DEFAULT_OPTION,
JOptionPane.PLAIN_MESSAGE,
resizedIcon,
options,
options[0]
);
return 1;
}
public void startTimer(boolean isWhite) {
timerManager.start(isWhite);
}
public void gameOverByTimeout() {
// disable board input, show message
// JOptionPane.showMessageDialog(this, "Time's up! The game is over.");
}
}

View File

@ -1,70 +0,0 @@
package windowInterface;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.Timer;
public class TimerManager {
private int whiteSeconds = 300;
private int blackSeconds = 300;
private boolean whiteTurn = true;
private Timer timer;
private Runnable onTimeout;
private JLabel whiteLabel;
private JLabel blackLabel;
public TimerManager(JLabel whiteLabel, JLabel blackLabel, Runnable onTimeout, int time) {
this.whiteLabel = whiteLabel;
this.blackLabel = blackLabel;
this.onTimeout = onTimeout;
this.whiteSeconds = time;
this.blackSeconds = time;
timer = new Timer(1000, e -> tick());
}
public void start(boolean whiteStarts) {
this.whiteTurn = whiteStarts;
timer.start();
}
public void switchTurn() {
whiteTurn = !whiteTurn;
}
private void tick() {
if (whiteTurn) {
whiteSeconds--;
updateLabel(whiteLabel, whiteSeconds);
if (whiteSeconds <= 0) timeout("White");
} else {
blackSeconds--;
updateLabel(blackLabel, blackSeconds);
if (blackSeconds <= 0) timeout("Black");
}
}
private void updateLabel(JLabel label, int seconds) {
int mins = seconds / 60;
int secs = seconds % 60;
label.setText(String.format("%s: %02d:%02d", label == whiteLabel ? "White" : "Black", mins, secs));
}
private void timeout(String player) {
timer.stop();
onTimeout.run(); // you define what happens on timeout
JOptionPane.showMessageDialog(null, player + " ran out of time! Game over.");
}
public void stop() {
timer.stop();
}
public void reset(int time) {
whiteSeconds = time;
blackSeconds = time;
updateLabel(whiteLabel, whiteSeconds);
updateLabel(blackLabel, blackSeconds);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 367 KiB

View File

@ -1,2 +0,0 @@
# OOP_2B1_Project