28 Apr Java Programming Language Using The Processing Library For Graphics
At Programming Homework Tutors, we believe in providing our students with practical, real-world examples of how to apply the concepts they learn in class. That’s why we’ve developed a variety of sample projects to help you see how our courses can be used to create impactful solutions in your field of study.
Gameplay
The game contains a number of entities that will need to be implemented within your application.
Board
The board consists of a grid of tiles 14×14. Each tile is 48×48 pixels, so the total is 672×672 pixels. However, there are 120 pixels on the right sidebar reserved for information such as timers showing the number of minutes and seconds remaining on each player’s clock, and warnings or other messages for the user. The window size is therefore 672×792.
The board is arranged in a checkerboard pattern as below with alternating black and white tiles. These are fixed and do not change. Pieces sit atop these tiles, and the tiles may change colour shade to indicate highlights for particular reasons.
There are 4 main types of highlights:
Blue – the player clicked on a piece, and it is able to move to this square.
Light red – the currently selected piece can move to this square, capturing the current piece there
Green – the player’s currently selected piece
Yellow – the last piece to move, and the square it came from
Dark red – the king on this square is currently in check, or checkmate has occurred (pieces that contribute to the checkmate are highlighted in light red)
The piece layout is defined in a file named in the “layout” attribute of the JSON configuration file described below.
Config
The config file is in located in config.json in the root directory of the project. Use the simple json library to read it. Sample config and level files are provided in the scaffold.
The config sample as shown to the left, contains the name of the layout file. This is also located in the root directory of the project. The layout file will contain a grid of text characters, where each character represents the piece that should be in that cell. Uppercase characters are for black, and lowercase are for white. See the table below.
Layout file |
| See page 5 for images of movement | |||
Black | White | Chess piece | Value | Sprites | Movement |
P | p | Pawn | 1 |
| One space forward. Captures diagonally only. If blocked, cannot move. |
R | r | Rook | 5.25 |
| Horizontally and vertically. |
N | n | Knight | 2 |
| 2 squares vertical, 1 horizontal, or vice versa |
B | b | Bishop | 3.625 |
| Diagonally in any direction. |
H | h | Archbishop | 7.5 |
| Like Knight + Bishop |
C | c | Camel | 2 |
| 3 squares vertical, 1 horizontal, or vice versa |
G | g | General/Guard | 5 |
| Like Knight + King |
A | a | Amazon |
|
| Like Knight + Bishop + Rook |
K | k | King |
| 1 space in any direction. Cannot move into danger. | |
E | e | Chancellor | 8.5 |
| Like Knight + Rook |
Q | q | Queen | 9.5 | Like Bishop + Rook |
Empty spaces are empty tiles. All maps used for marking will be valid, but you should write your own tests for invalid maps and handle them as you see fit.
The “time_controls” section contains the amount of time to be given to player 1 and player 2 (player 2 is the computer – cpu). Seconds it the total time they start with, which is consumed while they are thinking about a move. The “increment” is a number in seconds added to their remaining time once they make a move.
The “player_colour” property denotes the colour of the pieces of player 1 (the human player). It should either have the value “white” or “black”. If player 1 is white, then player 2 is black. If player 1 is black, then player 2 is white. Whoever is white has the first move, as in regular chess.
Movement
The “piece_movement_speed” property in the config denotes how fast in pixels per frame a piece move should occur. This is limited by the “max_movement_time”, a number in seconds that the movement time should not exceed. If the movement would exceed this amount of time, the speed is increased to ensure it doesn’t take longer. Moves occur at a constant speed, with the chess piece smoothly transitioning in a straight line from its original position to its new position.
To trigger a move, the player must first select a piece by clicking on the cell it’s located in. Then, click to the cell the piece should move to. If the player instead selects one of their other pieces, then that piece becomes selected instead. If the player clicks on the selected piece again, or an invalid move, it becomes unselected.
Normal movement of pieces is described in the table above. The king, queen, bishop, knight, rook and pawn all have the same movement as in regular 8×8 chess. For the purposes of pawn movement, “forward” is considered going up the board for the human player, and going down the board for the computer player.
In addition, be mindful of the following special moves.
Special moves:
A pawn can move two squares forward if it is located on 2nd row from the top or bottom of the board (rank 2 and rank 13), and has not moved before.
A king may perform a ‘castling’ move if it has not moved before, which allows it to move two squares horizontally in either direction so long as there is also a rook towards the direction it will move (on the same rank), and that rook hasn’t moved. When this move is performed, the rook is placed on the other side of the king, adjacent to it.
Pawn promotion: When a pawn reaches the 8th rank (ie. when it crosses the halfway point on the 14×14 board), then it is promoted to a queen. It immediately turns into a queen and can be used as such in all subsequent moves
Only a camel or knight move may jump over pieces (or the rook when castling), and a player may not move a piece onto a cell already containing one of their own pieces. If a move causes the piece to enter a tile containing one of the opponent’s pieces, the opponent’s piece is ‘captured’ and removed from the board. All pieces capture on the same tiles as their regular movement, with the only exception being pawns which capture diagonally forwards instead, if there is a piece there. This is the only time they are allowed to move diagonally. If there is a piece directly in front of a pawn, it is blocked and cannot move to the cell occupied by that piece.
Examples of possible moves for each piece are shown below.
Figure 11: Queen movement
Check and Checkmate
If after a move, a king is under attack, the king is said to be in ‘check’. Under this circumstance, the player whose king is in check must do one of the following (all must already be legal moves):
Move their king to a safe square
Move a piece to block the attack
Capture the attacking piece
This is because otherwise, the player would lose their king on the next turn, and therefore lose the game. If none of these possibilities are available, then the player has been checkmated – there is no move available to them that would save their king, and they have lost.
When check occurs, the king’s square is highlighted in dark red, and the message “Check!” appears in the right sidebar. If a player attempts to make an otherwise legal move that doesn’t protect their king, display a message on the right sidebar: “You must defend your king!”, and the highlighted cell the king is on will flash 3 times with a duration of 0.5 seconds each.
A player cannot make a move that would result in their king coming under attack. This could be any of either:
- Moving the king to a square which is under attack by the opponent
- Moving a piece that is blocking an attack on their king by the opponent (this piece is said to be ‘pinned’)
Figure 13: The selected pawn is pinned by the archbishop, so cannot move. However if the archbishop was one space closer to it diagonally, then the pawn would be able to capture the archbishop but not move straight forward. If the king was on the square one space below where it currently is, then the camel would be pinned by the bishop.
Illegal moves due to check or pins should not be highlighted as blue tiles when selecting a piece to potentially move it – only legal moves should be highlighted.
Computer AI movement
The way the computer player determines moves is up to you. It can be as simple as choosing a move randomly out of all available legal moves. However, you should try and make it at least a bit intelligent. For example, here is guidance on some basic rules you might want to have:
Capture a piece if the piece’s value is higher than the capturing piece, and if multiple such options exist, choose the one with the highest difference
If a piece is threatened to be captured by a piece of lower value (or any piece if the threatened one is undefended), move it
Prefer to only move to squares that are not under attack by a piece of lower value (or even a piece of higher or equal value if the square is undefended) – let’s call these ‘safe squares’
If possible, attack the opponent’s king or a square adjacent to it if it’s not already under attack
If possible, checkmate the opponent’s king
If all else fails, choose a random move (prefer safe squares, but it’s possible none may be available)
Win and lose conditions
The game ends when either one player runs out of time, or their king is checkmated. Then other player wins.
If the human player wins by checkmate, display a message saying “You won by checkmate” in the right sidebar. If the human player wins due to the timer, display instead “You won on time”.
If the human player loses by checkmate, display a message saying “You lost by checkmate” in the right sidebar. If instead the cause was the timer, display “You lost on time”.
The player can also resign the game by pressing ‘escape’ on the keyboard. The game ends and the message “You resigned” is displayed in the right sidebar.
When the game ends, the board remains intact and frozen so that the player cannot make any moves (but may restart the game with the key press ‘r’). If checkmate occurred, the board should highlight the king of the checkmated player in red and the pieces contributing to checkmate in orange. Pieces contributing to checkmate are defined as a piece that is either attacking the king or one of the empty squares adjacent to it, or defending a piece that the king could otherwise capture. For each such square, there should only be one piece highlighted.
If there are no legal moves for a player, then the game is considered a draw and enters the end state. Display the message “Stalemate – draw”. Figure 14: The white king is checkmated. The contributing pieces are the archbishop and two pawns.
Application
Your application will need to adhere to the following specifications:
The window must have dimensions 672×792
The game must maintain a frame rate of 60 frames per second.
Your application must be able to compile and run on any the university lab machines (or Ubuntu VM) using gradle build & gradle run. Failure to do so, will result in 0% for Final Code Submission.
Your program must not exhibit any memory leak.
You must use the processing library (specifically processing.core and processing.data), you cannot use any other framework such as javafx, awt or jogl
You have been provided a /resources folder which your code can access directly (please use a relative path). These assets are loadable using the loadImage method attached to the PApplet type. Please refer to the processing documentation when loading and drawing an image. You may decide to modify these sprites if you wish to customise your game. You will be required to create your own sprites for any extensions you want to implement.
Disclaimer
The sample projects provided on our website are intended to be used as a guide and reference for educational purposes only. While we have made every effort to ensure that the projects are accurate and up-to-date, we do not guarantee their accuracy or completeness. The projects should be used at your own discretion, and we are not responsible for any loss or damage that may result from their use.
At Programming Homework Tutors, we are dedicated to helping students and educators achieve their goals by providing them with the resources they need to succeed. Our website offers a variety of tools and resources that can help you with the project mentioned above.
Whether you need help with research, project management, or technical support, our team of experts is here to assist you every step of the way. We offer online courses, tutorials, and community forums where you can connect with other learners and get the support you need to succeed.
If you’re looking to take your skills to the next level and make an impact in your field, we invite you to explore our website and see how we can help you achieve your goals.
Latest Topic
-
Cloud-Native Technologies: Best Practices
20 April, 2024 -
Generative AI with Llama 3: Shaping the Future
15 April, 2024 -
Mastering Llama 3: The Ultimate Guide
10 April, 2024
Category
- Assignment Help
- Homework Help
- Programming
- Trending Topics
- C Programming Assignment Help
- Art, Interactive, And Robotics
- Networked Operating Systems Programming
- Knowledge Representation & Reasoning Assignment Help
- Digital Systems Assignment Help
- Computer Design Assignment Help
- Artificial Life And Digital Evolution
- Coding and Fundamentals: Working With Collections
- UML Online Assignment Help
- Prolog Online Assignment Help
- Natural Language Processing Assignment Help
- Julia Assignment Help
- Golang Assignment Help
- Design Implementation Of Network Protocols
- Computer Architecture Assignment Help
- Object-Oriented Languages And Environments
- Coding Early Object and Algorithms: Java Coding Fundamentals
- Deep Learning In Healthcare Assignment Help
- Geometric Deep Learning Assignment Help
- Models Of Computation Assignment Help
- Systems Performance And Concurrent Computing
- Advanced Security Assignment Help
- Typescript Assignment Help
- Computational Media Assignment Help
- Design And Analysis Of Algorithms
- Geometric Modelling Assignment Help
- JavaScript Assignment Help
- MySQL Online Assignment Help
- Programming Practicum Assignment Help
- Public Policy, Legal, And Ethical Issues In Computing, Privacy, And Security
- Computer Vision
- Advanced Complexity Theory Assignment Help
- Big Data Mining Assignment Help
- Parallel Computing And Distributed Computing
- Law And Computer Science Assignment Help
- Engineering Distributed Objects For Cloud Computing
- Building Secure Computer Systems Assignment Help
- Ada Assignment Help
- R Programming Assignment Help
- Oracle Online Assignment Help
- Languages And Automata Assignment Help
- Haskell Assignment Help
- Economics And Computation Assignment Help
- ActionScript Assignment Help
- Audio Programming Assignment Help
- Bash Assignment Help
- Computer Graphics Assignment Help
- Groovy Assignment Help
- Kotlin Assignment Help
- Object Oriented Languages And Environments
- COBOL ASSIGNMENT HELP
- Bayesian Statistical Probabilistic Programming
- Computer Network Assignment Help
- Django Assignment Help
- Lambda Calculus Assignment Help
- Operating System Assignment Help
- Computational Learning Theory
- Delphi Assignment Help
- Concurrent Algorithms And Data Structures Assignment Help
- Machine Learning Assignment Help
- Human Computer Interface Assignment Help
- Foundations Of Data Networking Assignment Help
- Continuous Mathematics Assignment Help
- Compiler Assignment Help
- Computational Biology Assignment Help
- PostgreSQL Online Assignment Help
- Lua Assignment Help
- Human Computer Interaction Assignment Help
- Ethics And Responsible Innovation Assignment Help
- Communication And Ethical Issues In Computing
- Computer Science
- Combinatorial Optimisation Assignment Help
- Ethical Computing In Practice
- HTML Homework Assignment Help
- Linear Algebra Assignment Help
- Perl Assignment Help
- Artificial Intelligence Assignment Help
- Uncategorized
- Ethics And Professionalism Assignment Help
- Human Augmentics Assignment Help
- Linux Assignment Help
- PHP Assignment Help
- Assembly Language Assignment Help
- Dart Assignment Help
- Complete Python Bootcamp From Zero To Hero In Python Corrected Version
- Swift Assignment Help
- Computational Complexity Assignment Help
- Probability And Computing Assignment Help
- MATLAB Programming For Engineers
- Introduction To Statistical Learning
- Database Systems Implementation Assignment Help
- Computational Game Theory Assignment Help
- Database Assignment Help
- Probabilistic Model Checking Assignment Help
- Mathematics For Computer Science And Philosophy
- Introduction To Formal Proof Assignment Help
- Creative Coding Assignment Help
- Foundations Of Self-Programming Agents Assignment Help
- Machine Organization Assignment Help
- Software Design Assignment Help
- Data Communication And Networking Assignment Help
- Computational Biology
- Data Structure Assignment Help
- Foundations Of Software Engineering Assignment Help
- Mathematical Foundations Of Computing
- Principles Of Programming Languages Assignment Help
- Software Engineering Capstone Assignment Help
- Algorithms and Data Structures Assignment Help
No Comments