Ultimate Tic Tac Toe

Monkey Archive Forums/Monkey Projects/Ultimate Tic Tac Toe

Shockblast(Posted 2013) [#1]
Hey guys :)

I made an Ultimate Tic Tac Toe Game using Monkey and uploaded it on the Google Play Store. You can find it here:

https://play.google.com/store/apps/details?id=com.shockblastapps.ultimatetictactoe

The game plays like a regular tic tac toe game, you need to get three in a row to win. But the playing field consists of one large board containing 9 smaller ones. Winning smaller boards will help you win the game.

One important rule in this game is that the place where you put your cross/circle will determine the location where the opposing player may put his cross/circle.

You can now play it in a 2 players mode or against the cpu.

So it would be great if you guys would give it a try and if you don't get the rules, you can find more detailed instructions here:

http://mathwithbaddrawings.com/2013/06/16/ultimate-tic-tac-toe/

#Edit: The game now has an AI to play against.


dragon(Posted 2013) [#2]
i thought first: oh no, not again tic tac toe...
but this idea is clever, i never see this version of tic tac toe before


How do you created the native combobox "Restart Game"?


Raz(Posted 2013) [#3]
Haha, that's surprisingly deep tactics wise. On the face of it, it's not that different to tic tac toe, but once you start having to think about the move two or three turns ahead it really gets you thinking.

If you can get AI working, great :) If you can get online multiplayer working, even better! (bonus points for letting players have more than one game on the go, in a play by email kind of way!)


Shockblast(Posted 2013) [#4]
@dragon It's the Androids native Alertdialog.
So you need to connect your Monkey code with a native java file that calls the Alertdialog. I can give you the code that I used together with a quick example of how to call it in Monkey if you really want it. I can probably do that tomorrow :)

@Raz I've almost got some AI working, it's not super good but enough to make you carefully think about your next move. I was actually thinking of using the multiplayer of Google Play Services. But they only support real time multiplayer and not the email kind of way which I also want. So I'll see what else I can find.


Shockblast(Posted 2013) [#5]
@dragon, Srry a bit late but as promised the code that I used to create the native "Restart Game" box. The box is an Android Alert Dialog, so you have to call it with native code.

So I use a Monkey file for all the external functions, the file includes the following code.
#If TARGET="android"
	Import "native/android.java" ' The file with your native code.
#End

Extern

#If TARGET="android"
	Function LaunchAlertDialog:Void(title:String, message:String, positivetext:String, posresponse:String, negativetext:String) = "ExternalFunctions.launchAlertDialog"
	Function GetAlertResponse:String() = "ExternalFunctions.getAlertResponse"
#End


Then you need a .java file that natively calls the Alertdialog. You also need a function that retrieves the response of the Alertdialog.
import android.app.AlertDialog;
import android.content.DialogInterface;

class ExternalFunctions {

	public static AlertDialog.Builder alert;
	public static String alertResponse = "";
	public static String rp = "";
		
	static void launchAlertDialog(String title, String message, String positivetext, String posresponse, String negativetext) {
		alert = new AlertDialog.Builder(BBAndroidGame.AndroidGame().GetActivity());
		alert.setTitle(title);
		alert.setMessage(message);
		rp = posresponse;
		
		alert.setNegativeButton(positivetext, new DialogInterface.OnClickListener() { 
			public void onClick(DialogInterface dialog, int whichButton) {   
				alertResponse = rp;
			}
		});
		
		alert.setPositiveButton(negativetext, new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int whichButton) {
				alertResponse = "";
			}
		});		
		
		alert.show();
	}
	
	static String getAlertResponse() {
		String response = alertResponse;
		alertResponse = "";
		return response;
	}
}


Then in the update loop of your game. You call the LaunchAlertDialog() function whenever the restart button is pressed. In addition, the update loop checks in each iteration if a response is found or not.
' Update Restart Button
Local response:Int = buttonRestart.ButtonClicked(event)
If(response = Self.buttonRestart.BUTTON_PRESSED)
	#If(TARGET="android")				
		LaunchAlertDialog("Restart Game", "Do you want to Restart?", "Restart", "restart", "Cancel")
	#End
End

' Alert Dialogs
#If(TARGET="android")		
	Local response:String = GetAlertResponse()
	If(response="restart")
		Print("Restart the game")
	End
#End


I hope this helps :) BTW to stay on topic, I updated the Ultimate Tic Tac Toe game with an AI, so you can play against the computer. Plus I did some bugfixes/force close issues for a word game called Word Pyramid that I made a while ago but never posted here, would be great if you check that one out too. You can find it in my signature ^^