48
Client-Server Backgammon variant player Petros Demetriou BSc Computer Science Supervised By Dr. Rizos Sakellariou Department of Computer Science University of Manchester, UK April 2016

Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

  • Upload
    others

  • View
    31

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

Client-Server Backgammon variant player

Petros Demetriou BSc Computer Science

Supervised By Dr. Rizos Sakellariou

Department of Computer Science University of Manchester, UK

April 2016

Page 2: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

2

Abstract

Client – Server Backgammon Variant Player

Author: Petros Demetriou

The dissertation shows the whole process of developing the Plakoto game by investigating each of the development stages, such as the background, the design, the implementation and the testing. The goal of the project was to computerize the game of Plakoto by developing specific features to support Multiplayer and Human vs. AI Players. In order to accomplish the Multiplayer mode, a Client – Server Interface was built along with some components to support the full functionality and apply the game’s rules. The Human vs. AI Players mode was accomplished by building some classes, which include mechanisms to control the AI Players and mechanisms to allow the user to control the Graphical User Interface. Also the latter mode makes use of the game’s rules in an independent way from the Multiplayer mode.

Page 3: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

3

Acknowledgements

I would like to thank my supervisor Dr. Rizos Sakellariou for the useful comments, remarks and engagement through the learning process of my third year project. I would also like to thank my second marker Dr. Liping Zhao for her feedback throughout the seminar and the presentation sessions. Finally, my deepest gratitude goes to my loved ones for their love, their unconditional support during my studies and for helping me put pieces together.

Page 4: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

4

Table of Contents 1 INTRODUCTION ................................................................................................. 7

1.1 CLIENT-SERVER BACKGAMMON VARIANT PLAYER OVERVIEW .......................... 7 1.2 INTRODUCTION TO VIDEO GAMES ...................................................................... 7 1.3 DEFINING BOARD GAMES .................................................................................. 7 1.4 INTRODUCING PLAKOTO .................................................................................... 8 1.5 AIMS OF THE PROJECT ....................................................................................... 9 1.6 SUMMARY .......................................................................................................... 9

2 BACKGROUND .................................................................................................. 10 2.1 OVERVIEW ....................................................................................................... 10 2.2 CLIENT – SERVER INTERFACE .......................................................................... 10

2.2.1 Client – Server Protocol ........................................................................... 11 2.3 ARTIFICIAL INTELLIGENCE PLAYER ................................................................. 11 2.4 SUMMARY ........................................................................................................ 12

3 DESIGN ................................................................................................................ 13 3.1 OVERVIEW ....................................................................................................... 13 3.2 PLAKOTO STRUCTURE ...................................................................................... 13 3.3 MULTIPLAYER DESIGN ..................................................................................... 14

3.3.1 Multiplayer Design: Server ...................................................................... 14 3.3.2 Multiplayer Design: Client ....................................................................... 16 3.3.3 Multiplayer Design: Graphical User Interface ........................................ 18 3.3.4 Multiplayer Design: Protocol ................................................................... 19

3.4 HUMAN VERSUS ARTIFICIAL INTELLIGENCE PLAYER DESIGN .......................... 20 3.4.1 Human VS AI Player Design: Human Client ........................................... 20 3.4.2 Human VS AI Player Design: AI Player Modes ....................................... 21

3.5 SUMMARY ........................................................................................................ 23

4 IMPLEMENTATION ......................................................................................... 24 4.1 OVERVIEW ....................................................................................................... 24 4.2 IMPLEMENTATION OVERVIEW .......................................................................... 24 4.3 DESCRIPTION OF IMPLEMENTATION PROCESS .................................................. 25

4.3.1 Server Implementation .............................................................................. 25 4.3.2 Protocol Implementation .......................................................................... 27 4.3.3 Client Implementation .............................................................................. 28 4.3.4 Client Thread Implementation .................................................................. 29 4.3.5 Multiplayer Graphical User Interface Implementation ............................ 30 4.3.6 Human vs. AI Players Graphical User Interface Implementation ........... 31 4.3.7 Artificial Intelligence Beginner Player Implementation ........................... 32 4.3.8 Artificial Intelligence Advance Player Implementation ........................... 33 4.3.9 Main Menu Graphical User Interface Implementation ............................ 35

4.4 SUMMARY ........................................................................................................ 35

5 PROJECT TESTING .......................................................................................... 36 5.1 OVERVIEW ....................................................................................................... 36 5.2 TESTING DESCRIPTION ..................................................................................... 36

Page 5: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

5

5.3 TESTING METHODS AND LEVELS ..................................................................... 36 5.4 TESTING PROCESS DESCRIPTION ...................................................................... 37 5.5 SUMMARY ........................................................................................................ 39

6 CONCLUSION .................................................................................................... 40 6.1 OVERVIEW ....................................................................................................... 40 6.2 DISSERTATION CONCLUSIONS .......................................................................... 40 6.3 APPROACH OVERVIEW ..................................................................................... 41 6.4 SUMMARY ........................................................................................................ 41

7 REFERENCES ..................................................................................................... 42 APPENDIX A ............................................................................................................. 44

1 SERVER CLASS .................................................................................................... 44 1.1 ServerThread Class Methods ...................................................................... 44

2 CLIENT CLASS METHODS .................................................................................... 44 3 PLAKOTOGUI CLASS METHODS .......................................................................... 45 4 CLIENTTHREAD CLASS METHODS ...................................................................... 46 5 PLAKOTGUIFORAI CLASS METHODS ................................................................. 46 6 AIPLAYER CLASS METHODS ............................................................................... 47 7 ADVANCEAIPLAYER CLASS METHODS .............................................................. 47 8 SERVERPROTOCOL CLASS METHODS .................................................................. 48

Table of Figures Figure 1: Starting points and movement direction of checkers.

(bkgm.com/variants/Plakoto.html) ........................................................................ 8Figure 2: Structure of the Project. The diagram shows the structure of the project and

how the project is split into subsections. ............................................................. 13Figure 3: Server Flowchart ......................................................................................... 15Figure 4: Client Flowchart .......................................................................................... 17Figure 5: Plakoto GUI First Draft ............................................................................... 18Figure 6: Protocol Flowchart ...................................................................................... 19Figure 7: Human Client Flowchart ............................................................................. 20Figure 8: Artificial Intelligence Players Flowchart .................................................... 21Figure 9: Server Connection Algorithm. .................................................................... 25Figure 10: Server Thread Algorithm .......................................................................... 26Figure 11: Protocol algorithm ..................................................................................... 27Figure 12: Client Mode selection, Connection to server and GUI selection Algorithm28Figure 13: Client Thread Algorithm .......................................................................... 29Figure 14: MousePressed, mouseReleased and mouseDragged general algorithm. ... 31Figure 15: Artificial Intelligence Beginner Player Algorithm .................................... 32Figure 16: AI Advance Player Algorithm ................................................................... 33Figure 17: Rules defined in Rule-based system algorithm ......................................... 34Figure 18: Final Results of the 8 Rounds. .................................................................. 38

Page 6: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

6

Page 7: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

7

1 Introduction

1.1 Client-Server Backgammon variant player Overview

Plakoto is a popular Backgammon variant game in Greece. Two players can play the game and if the game is computerized, players can be humans or Artificial Intelligence players. The goal of the game is for the players to bring all their checkers to their home board and then bear them off. The player, who manages to bear off the checkers first, wins the game.

1.2 Introduction to Video Games A video game is a computerized game that involves one or more users interacting with an interface. In other words, it is a game played by electronically manipulating images produced by a computer program on a monitor.

Video games made their appearance in the early 1950s where computer scientists began designing simple low-level games as part of their research. Between the 1970s and 1980s video games became popular because of the introduction of arcade video games, gaming consoles and home computer games to the general public [1].

There are many types of video games such as board games, role-playing games (RPG), first – person shooter games, educational games and many more. In this report we will concentrate on board games and that is because of the genre of our game Plakoto.

1.3 Defining Board Games A board game, such as Plakoto, involves moving checkers or other pieces on a pre-marked surface, called board, according to the rules of each game. Some board games are based on strategy or pure luck or both. Plakoto is based on both strategy and luck.

Page 8: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

8

Board games usually have one or more goals that the players aim to achieve. Early board games represented a battle between two armies, and most modern board games are still based on defeating opposing players in terms of counters, winning position, or accrual of points [2].

1.4 Introducing Plakoto We already saw a brief overview of Plakoto (§ 1.1) but now it is time to further explain the game. The game can be played by exactly two players and each player has 15 checkers to start with; usually the checkers of player 1 are black and white for player 2. The checkers of each player are place on each player’s starting-point. Players have to move their checkers in a different direction on the board as shown in the figure below.

Figure 1: Starting points and movement direction of checkers. (bkgm.com/variants/Plakoto.html)

At the start of the game each player rolls a die and the one with the highest result starts first. Each player rolls the dice in turn and moves his/hers checkers according to the dice result. The player who has won a game starts the next game first. In Plakoto a checker can be placed only on an open point, which is a position that is not occupied by two or more checkers of the opponent. If the results of the dice are the same, called doubles, then the player must play twice. For example, a roll of 5-5 means that the player can use the five’s four times. Unlike in backgammon, hitting is not allowed in the game of Plakoto. Instead, if a player lands on a point occupied by an opponent’s single checker, the opponent cannot move his checker unless the player moves his checker; in other words the opponent’s checker is pinned.

Page 9: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

9

The mother-checker is the last checker on a player’s starting point and if the opponent manages to pin the mother-checker then the game overs and two points are awarded to the player that pinned the opponent’s mother-checker. After a player has moved all of his checkers on his home board bearing off starts. The player who manages to bear off his/hers checkers first wins the game and one point is awarded to the winner.

1.5 Aims Of the Project The objective of the project was to design and implement a server – client interface so that two users would be able to connect to the server through the client application and play the Plakoto game.

Furthermore, the most adventurous part of the project was to implement an Artificial Intelligence player so that users would have the opportunity to play against their computer.

In order to improve the whole experience of the users and make the game interesting and easy to use, a Graphical User Interface had to be designed and implemented according to the specifications of the game in the real world.

The requirements of the project were all implemented so I decided to design and implement a second more intelligent Artificial Intelligence player to provide the users with degrees of difficulty.

1.6 Summary This report discusses in detail the development of a computerized Backgammon variant game. Initially a brief introduction to video games (§ 1.2), board games (§ 1.3) and Plakoto (§ 1.4) is given. Also the aims of the project (§ 1.5) are stated. The report continuous by analyzing the background of the methods and tools used in Plakoto, by describing the design phase of the project and by explaining in depth the implementation phase in which all the components of the project are investigated. Later on, in order to demonstrate the final result of the project, the process of testing is discussed. Finally a conclusion is given that sums up the main facts of the project and also talks about any potential future work on the project.

Page 10: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

10

2 Background

2.1 Overview This chapter investigates the main components that the project is based on such as the client – server interface (§ 2.2), the artificial Intelligence player (§ 2.3) and other components that are crucial for the operation of the game.

2.2 Client – Server Interface The client server interface is a distributed application structure that separates tasks or workloads between the resource requesters, named clients, and resource providers, named servers. Clients and servers communicate with each other over a network, and the main goal of this particular interface is that the server shares information with the clients. The clients do not share any information with other clients; their main goal is to request resources and services from the server.

An early form of client–server architecture is the remote job entry, dating at least to OS/360 (announced 1964), where the request was to run a job, and the response was the output [3]. In the context of Plakoto, the server is a program that makes decisions according to the rules of the game. This means that the server is responsible for controlling the moves of the client, the dice as well as setting the game to its previous state if a wrong move was made. Another responsibility for the server is to replicate in real time the moves made by player one to the board of player two. The client program is responsible for sending request to the server in order to enable it to take specific actions. A type of request that the client would send to the server is when the user clicks on the roll dice button.

Page 11: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

11

2.2.1 Client – Server Protocol The client – server protocol is an important component needed for the communication between the clients and the server. One can think the protocol as a dictionary, which provides a structure for requests and answers between the two on the network. Another way to interpret protocol is to think it as a system of rules that allow the transmission of information between entities (server and client). These rules may define the syntax and the type of the communication. For example in the program of Plakoto, on a roll dice request send from the client to the server, the server will use the protocol as a reference in order to distinguish the type of request. In more detail, the server does not know what the client asks for before referencing the protocol. As soon as the protocol is used, the server will be able to understand the request and take the appropriate actions. Finally the server will use the protocol once more in order to answer to the client. Now it is the turn of the client to use the protocol in order to understand what the answer stands for.

2.3 Artificial Intelligence Player Artificial Intelligence (AI) is the process of development of computer systems able to perform tasks that usually require human intelligence, such as speech recognition, handwriting recognition, decision-making and translation between languages.

In the context of computer games, an Artificial Intelligence player is used to generate intelligent behaviors simulating human – like intelligence. In more detail, the computer is programmed to learn how to think as a human or to replicate the human behavior.

For example, a computer chess AI player calculates the best possible move according to the current state of the game and the way that each pawn can move and makes the best possible move in order to win the game.

In simple words, in Plakoto program, the artificial intelligence player poses as a human player that moves the checkers to the appropriate positions according to the dices.

The AI players address some crucial problems such as the problem of no Internet connection. This means that players from around the world can play the game without having to connect to the Internet. Another problem is when a user plays the game for the first time. With the help of the two AI

Page 12: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

12

modes the user will be able to learn how to play the game and in time to be able to compete with players from around the world.

2.4 Summary In this chapter we saw the most important components that the program requires in order to operate correctly. The client – server interface (§ 2.2) along with the client – server protocol (§ 2.2.1) are needed to support the multiplayer functionality. Also, the Artificial Intelligence player (§ 2.3) is needed in order to support the human versus computer mode. All of the components described above are investigated and analyzed in more detail over the next chapters.

Page 13: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

13

3 Design

3.1 Overview This chapter describes in full detail the project’s design process. Initially the structure of the process is investigated along with the most important components of the project. Then the remaining components of the project are discussed and analyzed.

3.2 Plakoto Structure After studying in depth the requirements of the project, in order to deliver the aims of the project a plan for the structure was made.

Figure 2: Structure of the Project. The diagram shows the structure of the project and how the project is split into subsections.

Plakoto

Multiplayer

Server

ServerImplementation Game'sRules

Protocol Client

ClientImplementation

GraphicalUserInterface

HumanvsArtiIicialIntelligenceplayer

HumanClientArtiIicial

IntelligencePlayerModes

ArtiIicialIntelligencePlayerBeginnerMode

ArtiIicialIntelligencePlayerAdvanceMode

Page 14: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

14

By looking at Figure 2 one can understand that the project is divided into two main phases. These phases are the Multiplayer mode and the Human versus Artificial Intelligence player mode. Each of the two main phases is divided to smaller subsections. The multiplayer phase contains the Server, the Client and the Protocol subsections. The Server subsection is then divided to the Server Implementation and the Game’s Rules subsections. The Client subsection is divided to the Client Implementation and the Graphical User Interface subsections. As we can see, the Human versus Artificial Intelligence player is divided to the Human Client and the Artificial Intelligence Player Modes subsections, which is then divided to the Beginner AI Player and the Advance AI Player.

3.3 Multiplayer Design In the next few pages, we are going to investigate the design and the general concept behind the subsections of the Multiplayer phase. Each subsection is explained and some of them contain flowcharts or other representations in order to help you to better understand the tasks of each subsection.

3.3.1 Multiplayer Design: Server The Server is the first component of the Multiplayer phase and its purpose is to connect to the specified port and listen for any requests from the client. The server does not know when the client will send a request so a mechanism needs to be designed in order for the server to keep listening for any incoming requests. The mechanism that will solve this problem is to use threads so the server will always listen. When a new request is send by the client, the server will have to identify the request by using the communication medium that is the Protocol subsection. As soon as the request is identified, the server carries out the necessary actions based on the type of the request and answers back to the client. This process is shown with the help of the following flowchart (Figure 3) that describes the processes carried out by the server.

Page 15: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

15

Figure 3: Server Flowchart

Page 16: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

16

Figure 3 shows the general processes that the Server carries out from the start to the end of the Server application. We can derive from the flowchart that the server keeps listening for incoming requests and also how the server behaves when no connection is made and when no request is send by the client.

3.3.2 Multiplayer Design: Client The second main component of the multiplayer phase is the Client subsection. The Client has to connect to the specified port that is the same as the port the server will connect to. The ports must be the same in order to establish a communication between the Server and the Client. On the event of successful connection of the Client to the Server, the Client initializes and generates the Graphical User Interface (GUI). The GUI is what the user sees on the screen and in that case the board of Plakoto, the checkers and the dice. The GUI is also responsible for listening for any incoming requests from the user such as rolling the dice or moving a checker. When a user takes an action on the GUI, the GUI identifies the request of the user and with the help of the Client implementation sends the request to the Server. We now face the problem of not knowing when the server will answer back. A solution to that is to use a thread that keeps listening for any answers from the server. When the Server comes with an answer, it sends the answer to the Client who uses the Protocol medium to identify it. Finally, after the identification, the appropriate changes to the GUI and the state of the game are made.

Page 17: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

17

Figure 4: Client Flowchart

Page 18: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

18

Figure 4 describes the general processes that the Client should follow. It also shows to us the need for the continuous listening of any requests coming from the user and any answers coming from the Server.

3.3.3 Multiplayer Design: Graphical User Interface The Graphical User Interface is everything that the user sees on the screen. In the case of Plakoto, the GUI is consisted of a board, the triangles - which are the positions the checkers can move on -, the checkers and the dice. The GUI also contains the ROLL button that is used to roll the dice.

Figure 5: Plakoto GUI First Draft Figure 5 shows the first draft that was drawn for the Graphical User Interface of Plakoto. The first draft visualizes the general idea of Plakoto and replicates the game’s board as it is in the real world. Some minor changes were made to the GUI upon the completion of the project.

Page 19: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

19

3.3.4 Multiplayer Design: Protocol The Protocol subsection operates as a medium between the Client and the Server. We can think the Protocol as a dictionary that is crucial for the communication of the two. As soon as the Server or the Client starts, the Protocol initializes the local variables and the defined types of data that the Server or Client can use in order to send or receive requests. Figure 6: Protocol Flowchart

Page 20: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

20

3.4 Human versus Artificial Intelligence Player Design The last few pages of the chapter investigate the design details of the Human versus Artificial Intelligence Player phase. As we can see from the structure of the project (Figure 2) this phase is consisted by the Human Client and the two Artificial Intelligence Players. The two modes, beginner and advance, provide the users with degrees of difficulties and add extra functionality to the project. This extra functionality is intended to make the project more interesting and fun.

3.4.1 Human VS AI Player Design: Human Client The Human client, which is under the Human VS AI player phase, is the client intended for being used by the users. It is the component that initializes the Graphical User Interface and contains the rules of the game needed for the behalf of the user. It manages all the requests coming from the user and checks them against the game’s rules. The requests can be rolling the dice, moving checkers and etc. The Human client then makes the appropriate changes to the GUI according to the requests of the user and the game’s rules. Figure 7: Human Client Flowchart

Page 21: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

21

Figure 7 shows the general process that is undertaken by the Human Client. It shows how the client handles any requests coming from the user, when the game’s rules are applied and the steps undertaken when a request is fulfilled.

3.4.2 Human VS AI Player Design: AI Player Modes The Artificial Intelligence Player Modes are responsible for playing against the user by applying the rules of the game and using some mechanisms in order to play the game. The following sections discuss in detail how they both achieve that and the different mechanisms that each mode uses. Figure 8: Artificial Intelligence Players Flowchart

Page 22: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

22

Figure 8 shows the general processes undertaken by both AI players; Beginner and Advance mode. Each AI Player mode uses a mechanism to move the checkers and play the game.

3.4.2.1 AI Player Modes: Beginner Mode The Beginner Mode of the AI Players is responsible for playing against a user by applying the game’s rules and by using a mechanism in order to play the game. This mechanism is responsible for selecting a checker and moving it according to the dice results. The mechanism goes through all the available checkers, checkers that are not pinned by the user or checkers that can move to the specified location always according to the dice results, and selects two random checkers to move. Then the Beginner mode moves the checkers and passes the turn to the Human client.

3.4.2.2 AI Player Modes: Advance Mode The Advance Mode of the AI Players uses a Rule – Based system in order to select the appropriate checkers and make the best possible moves. The rules specified in the rule – based system are listed below in a priority order:

• Select the checkers, which according to the dice results, will pin the opponent

• If the previous condition is not applicable, then according to the dice results select the checkers that will close any open points

• If the previous condition is not applicable, then according to the dice results select two checkers that can be placed on a position where no checker exists

• Finally, if the previous condition is not applicable, according to the dice results select two random checkers that can be moved.

The reason of using a rule – based system instead of any other mechanism is because the game is played based on the user’s gut. There is no correct technique or way to play the game so the rule – based system was selected in that does not restrict the gameplay of the Advance mode to a specific way of playing the game. The rules applied to the mechanism are some general rules that most players follow.

Page 23: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

23

3.5 Summary In this chapter the structure (§ 3.2) and the design of the project was investigated. The two main phases (§ 3.3, § 3.4) of the project along with their subsections were explained. Finally at the end of the chapter the two AI Player Modes (§ 3.4) were explained giving insights to the mechanisms used for each one of them (§ 3.4.2.1, § 3.4.2.2).

Page 24: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

24

4 Implementation

4.1 Overview This chapter explains the project’s implementation process. The implementation of the project’s components are explained along with the most important functions of each component. Each function is explained in detail by giving and explaining the function’s algorithm.

4.2 Implementation Overview The process of implementation is one of the most crucial phases in a project’s life cycle. That is because the specified process is the one responsible for building the project. It stands right after the design process and before the testing of the software. Its purpose is to translate all the models and decisions of the design process into working software. For the implementation of this project, an agile technique, called Task Board, was applied in order to divide the work that had to be done in fairly equal amount of work and to help manage the time spend for each task. The Task Board is a physical board with some columns and post-it notes. The post-it notes represent the tasks that are to be developed and the columns represent the phase that each task is at the moment. The board was consisted by the following columns: Backlog, To Do, In Progress, To Test and Done. Some task examples are: Establish Server – Client Communication, Implement the Server – Client protocol, Create the ‘Roll Dice’ button and etc. Finally, the task board helped me to identify the most important tasks of the project, so I was able to spend the correct amount of time needed according to the value of each task.

Page 25: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

25

4.3 Description Of Implementation Process This section investigates in detail the implementation of the project’s components along with the most important functions of each component. For the development of the project, the JAVA language was used.

4.3.1 Server Implementation The Server is one of the three subsections of the Multiplayer phase. As we saw before, the job of the server is to connect to a port, receive and send requests, and apply the game’s rules when undertaking actions for the received requests. However, the most important job of the server is to establish a connection to the specified port, because without the connection we have no server. Then by using sockets and streams, the server receives requests from the clients and answers back.

Ø Server Connection Algorithm:

Figure 9: Server Connection Algorithm.

Figure 9 shows how the server achieves connection and how it starts a new thread for every connected client. The next step is for each generated thread to listen for any requests coming from the clients and by following the game’s rules to formulate an answer and send it back to them. Each thread runs continuously independent of any others. The following figure (Figure 10) shows how a thread operates.

Page 26: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

26

Ø Server Thread:

Figure 10: Server Thread Algorithm

Both algorithms (Figure 9, Figure 10) along with the game’s rules are implemented in the class Server.java. The class also contains the following functions:

• synchronized void setOpponentsPrevioustLoc(float previousX, float previousY, int checkerToMove, int checkerPreviousPosition); This function is responsible for setting a checker on the opponents board (player B) to its previous location when a move made by player A it is not allowed.

• sendNumOfCheckersAtStartPoint(int num); This function is responsible for sending the number of the remaining checkers which are placed on the starting point.

• play(String player); This function is responsible for managing and notifying a player that is his/hers turn to play.

• sendDices(Dices dices, String player); Responsible for sending the randomized dice to the client

• checkIfClientsConnected(); Checks if two clients are connected and notifies them that the game can start.

• setOpponentsInitLoc(int checker); Method that sets the opponent’s checkers location.

• moveOppChecker(CheckerPosition position); This method is responsible for replicating the moves made by player A on the board of Player B in real time.

• sendMsg(int type, String msg); Method for sending text messages to the clients

• removeDisconnectedClients(String username); Method to remove any disconnected clients from the Client List.

Page 27: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

27

For the implementation of the Server.java class, the following packages where used:

• java.net package - Provides the classes for implementing networking applications.

• java.util package - Contains the collections framework, legacy collection classes, event model, date and time facilities, internationalization, and miscellaneous utility classes (a string tokenizer, a random-number generator, and a bit array).

• java.io - Provides for system input and output through data streams, serialization and the file system.

4.3.2 Protocol Implementation The Protocol is a medium for the communication of the server and the clients. It operates as a dictionary and its purpose is to make the job of the server and the client easier by identifying the type of the request. Without the protocol, both the server and the client would not be able to undertake the appropriate actions according to the type of request.

Ø Protocol Algorithm

Figure 11: Protocol algorithm

Figure 11 shows the algorithm for the protocol, which is implemented in the ServerProtocol.java class. The algorithm reveals that there is nothing complex about it; just the listing of the requests’ types and the creation of getter methods.

For the implementation of the ServerProtocol.java class the following packages were used:

• Java.io.Serializable - Object serialization where an object can be represented as a sequence of bytes that includes the object's data as well as information about the object's type and the types of data stored in the object.

• Java.util.Random – Responsible for randomizing two integers. The methods of the ServerProtocol.java class are listed in Appendix A.

Page 28: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

28

4.3.3 Client Implementation The second and the larger subsection of the Multiplayer phase is the Client. The Client is responsible for invoking the correct classes according to the user’s selection. For example, if the user selects to play the multiplayer mode then the necessary functions for connecting to the server, for sending requests to the server are invoked; if the user selects to play with one of the AI Players then the necessary functions for initializing the Human vs AI Player mode are invoked. Also, according to the user’s selection, the appropriate Graphical User Interface, along with the necessary functions for controlling it, are called.

Ø Client Mode selection, Connection to server and GUI selection Algorithm

Figure 12: Client Mode selection, Connection to server and GUI selection Algorithm

Figure 12 shows some of the operations carried out by the Client.java class and we can see what choices are made according to the user’s selection. On the event of selecting the multiplayer mode the associated GUI is called and the functions of the GUI listen for requests made by the user on the board. Then the requests are translated so the Client can send them to the Server. The Client also uses thread, which listens for any answers from the server. The thread is also responsible for translating and sending these answers to its assigned player’s Graphical User Interface.

Page 29: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

29

On the event of selecting one of the Human vs AI Player mode the client does not need to connect to the server, so there is no need for sending requests to the server. Instead, the client invokes the associated GUI for this type of game and the specified AI Player; the Client is also responsible for the control of the game as well as for the game’s rules application. For the implementation of the Client.java class, the following packages were used:

• java.net package - Provides the classes for implementing networking applications.

• java.util package - Contains the collections framework, legacy collection classes, event model, date and time facilities, internationalization, and miscellaneous utility classes (a string tokenizer, a random-number generator, and a bit array).

• java.io - Provides for system input and output through data streams, serialization and the file system.

• Javax.swing - Provides a set of "lightweight" (all-Java language) components that, to the maximum degree possible, work the same on all platforms.

The functions of the Client.java class are listed in Appendix A.

4.3.4 Client Thread Implementation The Client thread that its implementation is within the ClientThread.java class is invoked whenever the user chooses the Multiplayer mode. The purpose of the class is to continuously listen for any answer coming from the server and then according to the type of answer to execute certain actions such as passing information to the associated Graphical user Interface. Figure 13 shows the algorithm for the Client Thread.

Ø Client Thread Algorithm

Figure 13: Client Thread Algorithm

Page 30: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

30

4.3.5 Multiplayer Graphical User Interface Implementation

The multiplayer Graphical User Interface is implemented in the PlakotoGui.java class. The specified class contains multiple other classes - such as the Dice class, the GameComponents class, the Checkers class, the Rectangle class and the MoveObject class – that are associated with the drawing and the implementation of the Multiplayer GUI. The Dice class is responsible for displaying the image of the associated dice according to the dice results sent by the server. The Checkers class is responsible for drawing the checkers on the board of the GUI. The Rectangle class is responsible for drawing the rectangles that the user will use when he/she bears off the checkers.

The GameComponents class is responsible for drawing the board and the triangle of the board on the GUI.

Finally, the MoveObject class is the most important part of the PlakotoGui.class because it contains all the functionality of the GUI as it is the class that allows and controls the moves on the GUI. It is also responsible for passing any requests made by the user to the client, so the client will pass them on to the server. The MoveObject class contains some of the game’s rules such as the functionality required when the result of the dice is doubles (e.g.: 4-4). As mentioned above, the MoveObject class implements the functionality of the GUI. The methods mousePressed, mouseReleased and mouseDragged are the three responsible methods for the functionality supported by the MoveObject class. All the three methods have the same general algorithm with a difference in the first line. For the mousePressed the first line is as shown in Figure 14, for the mouseReleased the first line changes to “On the event of releasing the mouse and for the mouseDragged obviously the first line changes to “On the event of dragging the mouse”.

Page 31: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

31

Figure 14: MousePressed, mouseReleased and mouseDragged general algorithm.

4.3.6 Human vs. AI Players Graphical User Interface Implementation

The Human vs. AI Players Graphical User Interface is implemented in the PlakotoGuiForAI.java class. The implementation of the class is identical to the Multiplayer Graphical User Interface implementation but instead of passing the requests made by the user to the client in order to pass them on to the server, the Human vs. AI Players Graphical User Interface implementation just passes the requests to the Client.java class to control the game. This is because no server is needed for the implementation of the AI Players. This has the result of supporting a mode of the game that does not require any Internet connection giving the ability to all the users to play the game. The following packages were used for the implementation of the PlakotoGuiForAI.java as well as for the PlakotoGui.java:

• java.util package - Contains the collections framework, legacy collection classes, event model, date and time facilities, internationalization, and miscellaneous utility classes (a string tokenizer, a random-number generator, and a bit array).

• java.io - Provides for system input and output through data streams, serialization and the file system.

• java.awt - Contains all of the classes for creating user interfaces and for painting graphics and images.

• javax.imageio - The main package of the Java Image I/O API. • Javax.swing - Provides a set of "lightweight" (all-Java language)

components that, to the maximum degree possible, work the same on all platforms

Page 32: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

32

The methods of the PlakotoGuiForAI.java and PlakotoGui.java class are listed in Appendix A.

4.3.7 Artificial Intelligence Beginner Player Implementation

The Artificial Intelligence Beginner Player is implemented in the AIPlayer.java class. It is responsible for replicating the moves of a human and playing the Plakoto game on its own. The checkers to be moved are selected randomly by a list that contains all the checkers available to be moved. The class contains some of the game’s rules so the AI Beginner Player can play the game correctly. Another point worth mentioning is the Log file that the player produces. The Log file is very useful for monitoring the behavior of the player.

Ø Artificial Intelligence Beginner Player Algorithm

Figure 15: Artificial Intelligence Beginner Player Algorithm

Figure 15 shows the general process and operations followed by the AI Beginner Player.

Page 33: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

33

For the implementation of the AIPlayer.java class, the following packages were used:

• java.util package - Contains the collections framework, legacy collection classes, event model, date and time facilities, internationalization, and miscellaneous utility classes (a string tokenizer, a random-number generator, and a bit array).

• java.io - Provides for system input and output through data streams, serialization and the file system.

• java.awt - Contains all of the classes for creating user interfaces and for painting graphics and images.

The methods of the AIPlayer.java class are listed in Appendix A.

4.3.8 Artificial Intelligence Advance Player Implementation

The implementation of the Artificial Intelligence Advance Player is carried out in the AdvanceAIPlayer.java and it is identical to the implementation of the AI Beginner Player but instead of randomly selecting the checkers to be moved, the AI Advance Player uses a Rule – Based system. Another similarity to the AI Beginner Player is the Log file that helps to monitor the player’s behavior.

Ø Artificial Intelligence Advance Player Algorithm

Figure 16: AI Advance Player Algorithm

Page 34: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

34

The rules defined in the Rule – Based system responsible for the process of selecting two checkers are shown in Figure 17.

Ø Rule–Based System - Rules Algorithm

Figure 17: Rules defined in Rule-based system algorithm For the implementation of the AdvanceAIPlayer.java class, the following packages were used:

• java.util package - Contains the collections framework, legacy collection classes, event model, date and time facilities, internationalization, and miscellaneous utility classes (a string tokenizer, a random-number generator, and a bit array).

• java.io - Provides for system input and output through data streams, serialization and the file system.

• java.awt - Contains all of the classes for creating user interfaces and for painting graphics and images.

The methods of the AdvanceAIPlayer.java class are listed in Appendix A.

Page 35: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

35

4.3.9 Main Menu Graphical User Interface Implementation

The Main Menu Graphical User Interface was not mentioned in the Design chapter (§ 3) because it was outside of the scope of the project and the project’s requirements. The Main menu GUI was implemented in the Client.java class. The reason for implementing this component was to improve the user experience by building a simple GUI, which would help the users to choose the mode they wish to play.

4.4 Summary In this chapter we saw in detail the process of the project’s implementation. Each component of the project was discussed in detail along with its most important parts and algorithms. All the algorithms are given in high-level language to help the understanding of the readers. The next chapter discusses the Testing of the System.

Page 36: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

36

5 Project Testing

5.1 Overview This chapter discusses the project’s Testing phase. Initially a brief description of Software Testing is given, then an overview of the testing technique used follows and finally the testing process of the project is investigated along with some results.

5.2 Testing Description The testing process is a vital part of software development. The role of testing is to determine if the project delivered meets the specified requirements. It is the phase that will determine how useful is the final version of the software compared to the requirements. It is also the phase that will reveal any bugs of the software, so the developers will be able to fix them. However, it is very important to start the testing as early as possible and not only test the full software. That is because if testing starts early it will be very hard to deliver something that is not useful. Another point to mention is that if bugs are found early this will prevent any larger problems with the project.

5.3 Testing Methods and Levels In this section, the testing methods and testing levels used are described. The testing of the project was done in two levels; the Unit level and System level. The Unit testing refers to tests made to verify the functionality of a specific section of the project. System testing is the tests made on the completed project to evaluate if the system meets the specified requirements. The testing technique used for both levels was black - box testing. Black – box testing is a method of software testing that examines the functionality of

Page 37: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

37

an application without any knowledge of the internal implementation and without seeing the code. The testers only know what the system is supposed to do and not how it does it.

5.4 Testing Process Description The testing for both levels, unit and system, was carried out by real users that have extensive knowledge of the game. In unit testing, testers were given a part of the project and were informed what each part was supposed to do. They were testing the functionality of the game and also testing the components to see if they work as in the real world. When the project was fully completed, the testers were given the whole project in order to test its functionality. They extensively tested both the Multiplayer and AI Player modes. Both Unit and System testing were successful because they revealed crucial bugs that needed to be addressed. The project was repeatedly tested until its behavior was as it supposed to be. Except from the two tests mentioned above, an automated test was produced in order to test the AI Players. The purpose of this test was to clarify if the AI Advance Player is a stronger player than the AI Beginner Player. The test was repeated for 8 rounds. The result was that the AI Advance Player won all of the rounds. The figure on the next page (Figure 18) shows the result of the 8 rounds. In all 8 rounds, the AI Beginner Player is assigned to the black checkers and the AI Advance Player is assigned to the white checkers. As we can see, there are no white checkers on the board, just on the blue rectangle area, which is the area that the user places the checkers during the bearing off.

Page 38: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

38

Figure 18: Final Results of the 8 Rounds.

Page 39: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

39

5.5 Summary This chapter describes the testing process and the techniques followed for testing the project. It also describes the test carried out in order to distinguish which AI Player is the strongest one. The evidence given for the test (Figure 18) not only shows that the AI Advance Player is the strongest one, but it also shows that both AI Players operate, as they should. In the next chapter a conclusion is given summarizing the whole process of the project’s development.

Page 40: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

40

6 Conclusion

6.1 Overview This chapter concludes the dissertation by summarizing the process of developing the project from scratch. Then a small overview of the approach followed is given.

6.2 Dissertation Conclusions The dissertation shows the whole process of developing the Plakoto game by investigating each of the development stages, such as the background (§ 2), the design (§ 3), the implementation (§ 4) and the testing (§ 5). The goal of the project was to computerize the game of Plakoto by developing specific features to support Multiplayer and Human vs. AI Players. In order to accomplish the Multiplayer mode, a Client – Server Interface was built along with some components to support the full functionality and apply the game’s rules. The Human vs. AI Players mode was accomplished by building some classes, which include mechanisms to control the AI Players and mechanisms to allow the user to control the Graphical User Interface. Also the latter mode makes use of the game’s rules in an independent way from the Multiplayer mode. The mechanism used for the AI Beginner Player was to randomly select an available checker and move it according to the dice results. For the AI Advance Player, a smarter mechanism was used. This mechanism is known as Rule-Based System, which selects a checker according to the rules given in the system.

Page 41: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

41

6.3 Approach Overview In order to build the Plakoto project, a number of steps were followed. The first step was to perform some research in order to learn how games are developed, which Client – Server Interface fits for the project, how Java graphics and their components are used and finally how Artificial Intelligence players can be developed. Then the design and implementation of each component took place by following and agile technique, the Task Board. Finally, the testing of the whole project was conducted in order to discover and fix any bugs that affected the system. The agile technique applied, helped a lot with the development of the project because tasks were divided into smaller and easier to develop pieces. Finally, I want to mention that the final result fulfills more than the given requirements of the project and there are many improvements to be made and more functionality to be added than the developed one. An example of a functionality to be added is the chat room along with a database that stores the user information, the user messages and the high scores of each user. Also, improvements can be made to the Graphical User Interface of the game to support much modern graphics.

6.4 Summary In the last chapter of the project, a summary of the whole process is given (§ 6.2) along with a short overview of the approach followed (§ 6.3). By the end of the section §6.3, some examples of future work were given.

Page 42: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

42

7 References [1] History of Video Games

https://en.wikipedia.org/wiki/History_of_video_games [2] Board Games https://en.wikipedia.org/wiki/Board_game [3] Client – Server Model. Early history.

https://en.wikipedia.org/wiki/Client–server_model [4] Distributed Systems: Principles and Paradigms (2nd edition), by Andrew

S. Tanenbaum and Maarten Van Steen [5] Distributed Systems: Concepts and Design (5th edition) (shorthand

CDK5), by George Coulouris, Jean Dollimore, Tim Kindberg, Gordon Blair

[6] Computer Networking: A top-down approach, by Kurose and Ross [7] Java 2D Graphics, By Jonathan Knudsen [8] Introduction to Computer Graphics: Using Java 2D and 3D, by Frank

Klawonn [9] Fundamental 2D Game Programming with Java By Timothy Wright [10] Knowledge-Free and Learning-Based Methods in Intelligent Game

Playing, by Jacek Mandziuk [11] AI for Game Developers, By David M Bourg, Glenn Seemann

Page 43: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

43

[12] Logical Foundations for Rule-Based Systems, Pr. Antoni Ligêza [13] Java Threads, by Scott Oaks, Henry Wong [14] Java: Just in Time, By John Latham [15] Java Network Programming, by Elliotte Rusty Harold

Page 44: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

44

Appendix A

1 Server Class

1.1 ServerThread Class Methods

• ServerThread(Socket socket, ObjectInputStream readFromIn, ObjectOutputStream writeToIn) • run() • setOpponentsPrevioustLoc(float previousX, float previousY, int

checkerToMove, int checkerPreviousPosition) • sendNumOfCheckersAtStartPoint(int num) • play(String player) • sendDices(Dices dices, String player) • checkIfClientsConnected() • printCheckerLists() • setOpponentsInitLoc(int checker) • moveOppChecker(CheckerPosition position) • sendMsg(int type, String msg) • removeDisconnectedClients(String username)

2 Client Class Methods

• Client() • connectActionPerformed(java.awt.event.ActionEvent evt) • genericRulesItemMousePressed(java.awt.event.MouseEvent evt) • quitPlakotoItemMousePressed(java.awt.event.MouseEvent evt) • aboutPlakotoItemMousePressed(java.awt.event.MouseEvent evt) • getDices(String player) • finishGame(String player, int score) • finishedMove(String color) • acknowledge() • initChecker(int checker) • checkFirstMoves(TriangleChecker triangleChecker) • moveOppCheckers(CheckerPosition position)

Page 45: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

45

• setToPreviousLoc(float checkerPreviousX, float checkerPreviousY, int checkerToMove, int checkerPreviousPosition) • sendNumStartingPoint(int numOfCheckers) • setCheckerTriangle(TriangleChecker checkerTriangle) • checkFirstMovesAI(TriangleChecker triangleChecker) • setCheckerTriangleAI(TriangleChecker checkerTriangle) • getDicesAI(String player) • play(String player) • sendNumStartingPointAI(int numOfCheckers) • setToPreviousLocAI(float previousX, float previousY, int

checkerToMove, int checkerPreviousPosition) • finishedMoveAI(String color)

3 PlakotoGui Class Methods

• PlakotoGui(boolean AIPlayer) • initGui() • terminateGui() • printDices() • Dices() • actionPerformed(java.awt.event.ActionEvent evt) • displayMsg(String msg) • showDices(int dice1, int dice2) • paintComponent(Graphics g) • GameComponents() • Rectangle(float x, float y, float width, float height) • isHit(float x, float y) • Checkers(float x, float y, float width, float height) • setInitialLocation() • setPreviousLocation(float previousX, float previousY) • addX(float x) • addY(float y) • setX(float x) • setY(float y) • returnX() • returnY() • addWidth(float w) • addHeight(float h) • getPoint() • createTriangle(Polygon triangle) • createTriangleReverse(Polygon triangle) • mousePressed(MouseEvent e) • mouseReleased(MouseEvent e)

Page 46: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

46

• mouseDragged(MouseEvent e) • moveOppCheckers(float dx, float dy, int checker) • checkForAvailableMoves(int firstDice, int secondDice) • checkDice1(int firstDice) • checkDice2(int secondDice) • alllowMoveWhenMoreThan2OnSameTriangle(int attemptedPosition, int

checkerToMove) • findCheckerOnTop(int checkerToMove) • getCheckersList() • getTrianglesList()

4 ClientThread Class Methods

• ClientThread(Socket socket, ObjectInputStream clientSocketInputStream) • run()

5 PlakotGuiForAI Class Methods

• PlakotoGuiForAI(boolean AIPlayer) • initGui() • terminateGui() • printDices() • Dices() • actionPerformed(java.awt.event.ActionEvent evt) • displayMsg(String msg) • showDices(int dice1, int dice2) • paintComponent(Graphics g) • GameComponents() • Rectangle(float x, float y, float width, float height) • isHit(float x, float y) • Checkers(float x, float y, float width, float height) • setInitialLocation() • setPreviousLocation(float previousX, float previousY) • addX(float x) • addY(float y) • setX(float x) • setY(float y) • returnX() • returnY() • addWidth(float w) • addHeight(float h) • getPoint() • createTriangle(Polygon triangle)

Page 47: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

47

• createTriangleReverse(Polygon triangle) • mousePressed(MouseEvent e) • mouseReleased(MouseEvent e) • mouseDragged(MouseEvent e) • moveOppCheckers(float dx, float dy, int checker) • checkForAvailableMoves(int firstDice, int secondDice) • checkDice1(int firstDice) • checkDice2(int secondDice) • alllowMoveWhenMoreThan2OnSameTriangle(int attemptedPosition, int

checkerToMove) • findCheckerOnTop(int checkerToMove) • getCheckersList() • getTrianglesList()

6 AIPlayer Class Methods

• AIPlayer() • play() • checkersAtEnd(int count, int checkerToMove) • alllowMoveWhenMoreThan2OnSameTriangle(int attemptedPosition, int

checkerToMove) • findCheckerOnTop(int checkerToMove) • getCheckerToMovePosition(int checker) • getCheckerToMove(int finalCounter, int counter, int die) • rollDicesForFirstTime() • printToFile(Object object) • displayMsg(String msg) • printDices(int die1, int die2) • finishedMove(String color) • setCheckerTriangle(TriangleChecker checkerTriangle)

7 AdvanceAIPlayer Class Methods

• AdvanceAIPlayer() • play() • checkersAtEnd(int count, int checkerToMove) • allowMoveWhenMoreThan2OnSameTriangle(int attemptedPosition, int

checkerToMove) • findCheckerOnTop(int checkerToMove) • getCheckerToMovePosition(int checker) • getCheckerToMove(int finalCounter, int counter, int die) • rollDicesForFirstTime() • printToFile(Object object)

Page 48: Client-Server Backgammon variant player reportstudentnet.cs.manchester.ac.uk/resources/library/3... · 1.1 Client-Server Backgammon variant player Overview Plakoto is a popular Backgammon

48

• displayMsg(String msg) • printDices(int die1, int die2) • finishedMove(String color) • setCheckerTriangle(TriangleChecker checkerTriangle)

8 ServerProtocol Class Methods

• ServerProtocol(int type, String message) • ServerProtocol(int type, boolean play) • ServerProtocol(int type, String message, String player) • ServerProtocol(int type, Dices message, String player) • ServerProtocol(int type, int integer) • ServerProtocol(int type, float checkerPreviousX, float checkerPreviousY,

int checkerToMove, int checkerPreviousPosition) • ServerProtocol(int type, TriangleChecker triangleChecker) • ServerProtocol(int type, CheckerPosition position) • getCheckerPreviousX() • getCheckerPreviousY() • getCheckerPreviousPosition() • getDices() • getCheckerToMove() • getCheckerPosition() • getAcknowledge() • getPlayPerm() • getMessageType() • getMessage() • getPlayer() • getInteger() • getTriangleCheckerNo()