Multiplayer TicTacToe

Project  Link on Github

This project was undertaken as part of my Distributed Systems class in college. The goal of the project was to create a game of TicTacToe that could be played on two different platforms and played cross platform. This project was completed with another person in my class. I wrote the java client for the game while he wrote an android app to play the game. We wrote the server code in python together and used mysql for our database.

The first step was to create the individual clients to play the game locally. I had to create a java client using the swing library for graphics. This wasn’t too hard task as I had experience with the library in previous projects. I had to have a game screen which could be used to play games, a lobby screen used to join games and a login/register screen to log in to the system.

gamelobby

We then had to create the server code. We wrote python scripts and hosted them using XAMPP on one of our laptops. The python scripts were written for each part of the system, to login users, register users, join games, create games, update games and get leaderboard statistics. Each script interacted with the database using mysql and sent the result back to the client using json. We then had a json parser to get the results in the client and check and use each part.

 

games  users

 

The clients are able to play cross platform as they both access the server in the same way. This means a user can play on either platform and play opponents on either platform. Game states are updated on the server and update all the clients connected to a game. All the code can be seen on github as well as more screen shots and the full report of the project at this link

login

 

 

Tagged , , , ,

Grifball Manager

I really enjoy the sports management genre to play and likewise I’m really interested in creating games in this genre too. I expanded on things I learned from my Hurling Management game here. The game is based on the game mode Grifball from the Halo series. The goal is simple to get the ball (bomb) into the enemies goal. You can kill your enemies and they will respawn and the game is played in teams. I added a few things to improve the management side of things of the game. For example substitutions can be made in between rounds.

The game simulates rounds of grifball with each team trying to get the ball into the goal. Each tick is 3 seconds and simulates the actions of each player in the game. Players can move in 4 directions, attempt to kill another player if they are in range or do something with the ball if they have possession of it. Their actions are decided by the positions and the roles given to them by the manager. Each of these made it more likely or less likely for them to take certain actions in the game. For example an Attacker set to Berserker is going to try kill everything on the map and does not care about the ball and a Full Defender will hang back even when the ball goes up to be ready on defence if the ball is turned over.

Positions – Role 1 – Role 2 – Role 3

Attacker – Normal – Berserker – Scoring

Scorer – Normal – Full – Playmaker

Defender – Normal – Full – Dynamic

Grifball_01

 

 

Decision making is done using arrays to store the probabilities of actions and then running random numbers to get the outcome. This is done for each player and they are all updated for each tick. The round will simulate and then give a result to the player at the end. They can then make tactical changes depending on how it went, either by changing positions, mentality or by subbing in new players for the next round. It keeps going until one team wins 4 rounds.

 

Grifball_02

Grifball_03

I have also added a simple tournament mode that can have 4 teams play a 2 round knockout tournament. The teams can be selected and the CPU matches will simulate while the player can play his/her own matches. Single matches can also be played in two player mode where the second team can also be user controlled by someone else. Both players set up their tactics independently and start the match to see who wins.

The code can be found on github

Grifball_04

Grifball_05

Tagged , , , , ,

Hurling Simulation Update and Great Game

After running a plenty of simulation and tweaking numbers I am quite happy with the outputs that the engine generates now. I have moved from generic tests to making some actual teams based on the county teams. The way teams are read into the program has been altered. Now there are two files, one which holds the full roster/panel for a team and the other which names the team to actually play the game. The former holds the ratings for each player and eventually stats when they get stored. The latter simply states the number, position and name of the player with the tactic and free taker at the top.
Sample roster and teamsheet
Eoin Murphy,18,1,1,1
Paul Murphy,1,17,2,2
JJ Delaney,1,19,3,1
Jackie Tyrrell,1,18,3,2

L
12
1,GK,Eoin Murphy
2,FB,Paul Murphy
3,FB,JJ Delaney
4,FB,Jackie Tyrrell

Two changes to the calculations behind the scenes were the addition of Home Bonus and greater emphasis on passing. In most sports there is some home field advantage and this is no different. The first team is designated as the Home team and they get a bonus to their total probability of having an event. The passing is based on the midfield stat of players. It was always factored into the total but now the total takes in double the midfield rating. This is to factor in that a better midfield and passing team would have more possession of the ball. This change has improved numbers a lot I feel and makes sense logically too.

Below I have pasted in a game I simulated today for the Hurling League Final between Kilkenny and Tipperary. It turned into a great game and shows off what a full game simulated is like.

MIN 0) Michael Fennelly finds himself unmarked and slots the ball between the posts.
0-1 TO 0-0
MIN 1) Eoin Murphy misses the catch but Cillian Buckley helps him out and scores a point from the loose ball.
0-2 TO 0-0
MIN 2) Cillian Buckley finds himself unmarked and slots the ball between the posts.
0-3 TO 0-0
MIN 5) Cillian Buckley is dragged down and Eoin Larkin converts the free.
0-4 TO 0-0
MIN 6) Noel McGrath finds himself unmarked and slots the ball between the posts.
0-4 TO 0-1
MIN) 9 Shane McGrath is about to shoot but JJ Delaney gets in the way and makes the block.
MIN) 12 JJ Delaney makes a great block stopping a sure point.
MIN 14) The ball is sent over the bar by Lar Corbett.
0-4 TO 0-2
MIN) 17 Aidan Fogarty is about to shoot but Paul Curran gets in the way and makes the block.
MIN 18) Seamus Callanan finds himself unmarked and slots the ball between the posts.
0-4 TO 0-3
MIN 19) Cillian Buckley catches the pass from Jackie Tyrrell, gets past his man and adds another point.
0-5 TO 0-3
MIN 21) Richie Hogan catches the pass from Colin Fennelly, gets past his man and adds another point.
0-6 TO 0-3
MIN 22) A good passing move ends with Lar Corbett and he scores a point for the team.
0-6 TO 0-4
MIN 23) And its a point from Cillian Buckley.
0-7 TO 0-4
MIN 24) Richie Hogan takes his point.
0-8 TO 0-4
MIN 25) Eoin Kelly scores a free from a tough angle.
0-8 TO 0-5
MIN 26) The loose ball is picked up by Shane McGrath who picks out Lar Corbett and its stuck over the bar.
0-8 TO 0-6
MIN 27) Richie Hogan makes a great catch and scores a point on the turn.
0-9 TO 0-6
MIN 32) A good passing move ends with Patrick Maher and he scores a point for the team.
0-9 TO 0-7
MIN 34) Michael Fennelly took a nasty blow across his arm but Eoin Larkin scores the free.
0-10 TO 0-7
HALF TIME SCORE: 0-10 TO 0-7
MIN 37) The loose ball is picked up by Conor O'Mahony who picks out Noel McGrath and its stuck over the bar.
0-10 TO 0-8
MIN 38) A loose sliotar is picked up by Shane Bourke and he puts it over the bar.
0-10 TO 0-9
MIN 39) The loose ball is picked up by Seamus Callanan who picks out Shane Bourke and its stuck over the bar.
0-10 TO 0-10
MIN) 41 A close call but Brendan Maher clears the ball away.
MIN 43) A soft free is given by the ref and Eoin Kelly scores it.
0-10 TO 0-11
MIN 44) The ref blows his whistle and Eoin Kelly scores the free from the 65.
0-10 TO 0-12
MIN 45) Conor O'Brien won the ball from his man and set up Shane Bourke for the good score.
0-10 TO 0-13
MIN 46) Lester Ryan won the ball from his man and set up Michael Fennelly for the good score.
0-11 TO 0-13
MIN 48) A soft free is given by the ref and Eoin Larkin scores it.
0-12 TO 0-13
MIN 49) Eoin Larkin makes a great catch and scores a point on the turn.
0-13 TO 0-13
MIN 50) A good passing move ends with Colin Fennelly and he scores a point for the team.
0-14 TO 0-13
MIN) 52 A clearance is caught by JJ Delaney and he sends it right back.
MIN 54) Brendan Maher passes the ball to Lar Corbett and its hit between the posts.
0-14 TO 0-14
MIN 55) Michael Rice takes his point and the goals will come.
0-15 TO 0-14
MIN 56) A soft free is given by the ref and Eoin Kelly scores it.
0-15 TO 0-15
MIN 60) Somehow Lester Ryan comes out with the ball and scores a nice point.
0-16 TO 0-15
MIN 62) A good passing move ends with Brendan Maher and he scores a point for the team.
0-16 TO 0-16
MIN 63) Patrick Maher makes a great catch and scores a point on the turn.
0-16 TO 0-17
MIN 64) The loose ball is picked up by Padriac Maher who picks out Seamus Callanan and its stuck over the bar.
0-16 TO 0-18
MIN 65) Paul Murphy passes the ball to Cillian Buckley and its hit between the posts.
0-17 TO 0-18
MIN) 66 A clearance is caught by Cillian Buckley and he sends it right back.
MIN 67) Darren Gleeson hits the ball to the unmarked Noel McGrath on the sideline, who sends it over the bar.
0-17 TO 0-19
MIN 70) The ball is picked up by the sideline by Michael Rice he solos past two men and hits it past the goalie.
1-17 TO 0-19
FINAL SCORE: 1-17 TO 0-19
kilkenny
1 Eoin Murphy: 0-0
2 Paul Murphy: 0-0
3 JJ Delaney: 0-0
4 Jackie Tyrrell: 0-0
5 Tommy Walsh: 0-0
6 Brian Hogan: 0-0
7 Kieran Joyce: 0-0
8 Lester Ryan: 0-1
9 Michael Fennelly: 0-2
10 Cillian Buckley: 0-5
11 Michael Rice: 1-1
12 Eoin Larkin: 0-4
13 Colin Fennelly: 0-1
14 Richie Hogan: 0-3
15 Aidan Fogarty: 0-0
tipp
1 Darren Gleeson: 0-0
2 Michael Cahill: 0-0
3 Conor O'Mahony: 0-0
4 Paul Curran: 0-0
5 Kieran Bergin: 0-0
6 Padriac Maher: 0-0
7 Conor O'Brien: 0-0
8 Brendan Maher: 0-1
9 Shane McGrath: 0-0
10 Eoin Kelly: 0-4
11 Lar Corbett: 0-4
12 Patrick Maher: 0-2
13 Shane Bourke: 0-3
14 Seamus Callanan: 0-2
15 Noel McGrath: 0-3

Tagged , , ,

Hurling and Update

Hurling

I realised after my two posts so far about my match engine that a lot of people are unaware of what hurling is. Unless you are from Ireland you probably dont know what it is. Well its a sport that comes from Ireland and is probably one of the oldest sports in the world. Its a field sport of two teams each with 15 players. You win by outscoring your opponent. Scoring is done by putting the ball over the goals but between the two side posts which is one point or into the goals which is a goal but considered 3 points. The game is played with a wooden stick and small ball. You control the ball and hit the ball using the stick. You can also hold the ball in your hand but for a limited amount of time.

There is one goalie on each team and then every other player matches up to an opponent and you mark him for the match (or until some change happens). There are 6 defenders, two midfielders and 6 forwards. Tackling is done by shouldering your opponent or sticking your hurley in the way to knock the ball loose. Its a very physical sport and a very fast sport. A match is made up of two halves each 30 or 35 minutes long. A team can use three subs in a match to replace players on the field already. The field is quite long at 135-145m.

Thats a quick overview of the sport and I encourage you to find out more or watch videos if you are interested as it is one of the best sports in the world. I may be biased but the amount of speed, skill, strength and everything that goes into the game makes it one of the most enjoyable to watch and play.

A small update on the engine now. I am currently running a lot of simulations with varying teams to try and see how the results are turning out. The numbers seem good enough so far but Ill continue to tweak them to try improve accuracy. I have written a small program that will read in reports and then output stats such as average goals, points, wins per team to csv files. These are very handy for checking the numbers.

Tagged , , ,

Hurling Simulation Engine Update

I have continued work on my Hurling match engine over the last few days and have made some good progress. I have added more factors in to affect the overall simulation of events in a match. A teams attack and opponents defence now play a factor into scoring points and goals. Teams can also perform defensive plays which are affected by their defence. A goalie gets factored into the goal probability now.

teamOneTotalProb = 1.8 + ((teamOneAtk - teamTwoDef)/100) + ((teamOneAtk - teamTwoDef - teamTwo.getGoalKeeper())/100) + (teamOneDef/1000)
+ teamOnePointMod + teamOneGoalMod + teamOneDefMod - (2 * teamTwoDefMod);
teamOnePoint = 0.8 + ((teamOneAtk - teamTwoDef)/100) + teamOnePointMod - teamTwoDefMod;
teamOneGoal = teamOnePoint + 0.04 + ((teamOneAtk - teamTwoDef - teamTwo.getGoalKeeper())/100) + teamOneGoalMod - teamTwoDefMod;
teamOneDefence = teamOneGoal + 0.2 + (teamOneDef/1000) + teamOneDefMod;

Another large addition is the use of tactics for a team. There are 5 tactics to choose from: Attacking, Defensive, Long Ball, Short passing or Take points. They are designated as a single character at the start of a teamsheet and read in with the players. Each tactic counters two and is countered by two so it creates a nice rock paper scissors strategy. The bonus for countering your opponent is an increase to the teams probability of having an “event”. Each tactic also has an effect on the team depending on the strategy. They are laid out below.

Tactic Counters Countered By Bonus Minus
Attacking Defensive, Take Points Short Pass, Long Ball points, goals defence
Defensive Long Ball, Short Pass Take Points, Attacking Defence Points, goals
Long Ball Attacking, Short Pass Defensive, Take Point Goals Points
Short Pass Attacking, Take Points Defensive, Long Ball Possession None
Take Points Defensive, Long Ball Attacking, Short Pass Points Goals

Frees have also been added in as a subset of scoring. Now after its calculate that it was a score it then checks whether that score was a free or not. A free is always scored by the designated free taker who is written on the teamsheet aswell under the tactic.

if(event < teamOnePoint)
					{
						int free = (int)(Math.random() * 4);

						if(free > 0)
						{
							p = teamOne.getPlayers().get(playerEvent(teamOne, 37, 71, 91, 99)).getName();
							comment = commentary.getPointCom(p, teamOne);
						}
						else
						{
							p = teamOne.getFreeTaker().getName();
							comment = commentary.getFreeCom(p, teamTwo);
						}

						pointsOne++;
						score = true;
					}

Commentary lines look like this before being read in. <name> is replace by the player performing the action and <other> is a relevant other player involved in the play.

 

<name> hits it past the goalie and into the back of the net.
<name> catches the ball, turns and scores a goal.
The ball is picked up by the sideline by <name> he solos past two men and hits it past the goalie.
The sliotar is rifled past the goalie by <name>.
The ball is fumbled by the goalie and <name> pulls on it.
A good ball into the corner to <name> leads to a good shot past the goalie.
The ball is caught by <other> and he lays it off to <name> who scores a goal.
A fast pull by <name> and its a goal.
<other> breaks the high ball for <name> who hits it past the keeper.
A lucky break falls to <name> and he finishes the goal.

Tagged , , ,

WikiWar

WikiWar Download
WikiWar is now finished and is available to download on the app store. I have also had my code interview for the app with my lecturer and received an A1 for the project. I am very happy with how the project has turned out and this post is going to talk about the final game and what I worked on.

The purpose of the game is to use Wikipedia to get from one page to another. You are rated by speed or skill depending on the game mode you chose. The game modes are:

wikiwar1
Standard
: Get from a set start to a set end point and you are rated on how few clicks you use

Timed: Similar to standard but with different presets and you are rated on how fast you complete the levle

Random: Gets a random starting point from Wikipedia (it can be ANYTHING) and picks from a large random list of preset pages as your end

Multiplayer: Pass-and-Play between two people. One chooses the start and the other chooses the end. The winner is whoever uses fewer clicks

The variety of modes adds lots of different ways to play and keeps people interested longer.

While playing there are a few things that the player can do. They can read through the Wikipedia page looking for a relevant link on the webview. They also can click the question mark at the top to remind themself of where they are trying to get to. For a faster game you can use the search feature which allows you to search for a word on the page that you feel may help you complete the level.
wikiwar5

My main work was focused on the modes themselves. I started off by making the basic game activity and created the Standard mode. The menu and game activity were used by others to make the random mode and timed modes. They used the template and added in the appropriate code. I also worked on the multiplayer mode (previous post on this). I also worked on creating the win screen and displaying the stars to rate your performance.
wikiwar2 wikiwar3wikiwar4

Tagged , , ,

Hurling Simulation Engine

I have started on a new project to do in my spare time. Its based around two things I really enjoy, Hurling and sports simulation games. I have started writing an engine to simulate hurling matches and give out scores, stats and match reports. I started by looking at results over the last two years for matches to try get various stats such as goals per game and points per game. I then broke it into steps, first getting the right number of scores, then scores per team, then goals and points per team. Right now I am simulating results quite similar to real results.

The program takes in teamsheets from textfiles with the players listed in position. Each player has 4 ratings, goalie, defence, pass and attack, on a 1 to 20 scale. These determine how good each is in each position. Player abilities affect the overall team performance and the likelihood of each scoring. I am currently trying to alter the probabilities further so that the overall attacking skill affects the scores of a team as does the defence.

I also can read commentary in from textfiles and with some manipulation can output the action just performed. All these are put together and outputted to another file.

Sample Teamsheet
GK,GKA1,7,2,1,1
FB,FBA1,1,8,3,2
FB,FBA2,1,9,1,2
FB,FBA3,1,7,1,2
HB,HBA1,1,8,3,2
HB,HBA2,1,8,4,2
HB,HBA3,1,7,5,2
MF,MFA1,1,5,8,3
MF,MFA2,1,4,9,5
HF,HFA1,1,2,7,7
HF,HFA2,1,3,5,8
HF,HFA3,1,2,6,8
FF,FFA1,1,1,1,9
FF,FFA2,1,1,3,7
FF,FFA3,1,2,3,9

Sample Match Report

MIN) 0 The ball is sent over the bar by HFA1.
0-1 TO 0-0
MIN) 2 MFA1 picks up the sliotar and hits it over the bar.
0-2 TO 0-0
MIN) 7 WIDE
MIN) 9 The ball is sent over the bar by FFB2.
0-2 TO 0-1
MIN) 12 The ball is sent over the bar by MFB1.
0-2 TO 0-2
MIN) 13 FFB2 picks up the sliotar and hits it over the bar.
0-2 TO 0-3
MIN) 14 FFB3 catches the ball, turns and scores a goal.
0-2 TO 1-3
MIN) 17 MFA2 picks up the sliotar and hits it over the bar.
0-3 TO 1-3

 

Tagged , , ,

Wikiwar Complete

WikiWar Download

We have finished the project and I am quite pleased with the result. I may do a further write up on the complete app but for now here is a link to download and try it yourself.

 

Tagged , , ,

WikiWar: Multiplayer

I have been working on a multiplayer mode for the app WikiWar. We decided that a “pass and play” mode could be added into the game quite easily. Its base is still the same as a normal mode but there is some more stuff added. Before the game starts each player will get to select a wikipedia page from a lot of options. Player One will select the starting point and Player Two will select the end point. The game will then start.

First Player One will play through the game. When they reach the end point, the game will reset and Player Two will get to play through the game. A Popup box appears informing Player One to hand over the device. Each score is saved and then checks which is higher. The Activity that runs when a game ends now will display the winner.

private void showPopUp() {

AlertDialog.Builder helpBuilder = new AlertDialog.Builder(this);
helpBuilder.setTitle("Round Over");
helpBuilder.setMessage("Pass the device to Player Two");
helpBuilder.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {
stack.clear();
stack.push(startPoint);

loadWebView();
}
});

// Remember, create doesn't show the dialog
AlertDialog helpDialog = helpBuilder.create();
helpDialog.show();
}

 

if(url.equals(endPoint))
			{
				if(playerOne)
				{
					playerOne = false;
					countP1 = count;
					count = 0;
					current = startPoint;
					showPopUp();
				}
				else
				{
					String winner;
					countText.setText("You win");
					countP2 = count;
					if(countP1 > countP2)
					{
						winner = "Player One";
					}
					else if (countP2 > countP1)
					{
						winner = "Player Two";
					} else
					{
						winner = "NO ONE!! It's a draw!";
					}

					Intent intent = new Intent(MultiActivity.this, WinActivity.class);
					intent.putExtra("winner", winner);
					intent.putExtra("single", false);
					System.out.println("Working4");
	        		startActivity(intent);
				}

			}
Tagged , , ,

Android Development: Wikiwar

My latest project that Im working on is an app for a college project. Its a group project with two other people. Its called Wikiwar and its a game that users must navigate through wikipedia linking different pages together. I think it works well for the project as it combines some nice android development techniques with a fun game mechanic. My work has started on creating a leveled mode. The mode consists of a number of preset starting and ending points on wikipedia and the player is rated by how few “clicks” or links they use to get from start to end. Android development is somewhat different to normal programming but I enjoy it quite a bit.

I started by storing the urls to the pages in the strings.xml file. Then I created buttons on the menu activity. Then in the xml for the button I use android:onClick and load a method in the java file. This method starts the game activity and and passes in the two relevant urls from the strings.xml. Each button will have its own method to load the correct data to start the game.

public void loadFour(View v)
{
Resources res = getResources();
String start = res.getString(R.string.nfl); //load string from xml file
String end = res.getString(R.string.nhl);
Intent intent = new Intent(this,StandardActivity.class);// creating an intent to launch the about activity
intent.putExtra("start_url",start); // pass in url strings to activity
intent.putExtra("end_url", end);
startActivity(intent);
}

<Button
 android:id="@+id/levelFour"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignLeft="@+id/levelTwo"
 android:layout_below="@+id/levelThree"
 android:onClick="loadFour"
 android:text="@string/four" />

Tagged , , ,