plastygrove
|
 |
«
Posted
2012-11-23 13:07:33 » |
|
Well, I've been able to churn out my first game and it's just TicTacToe. It has been more difficult than I would like to admit. But I'm really happy with the way it turned out. Here's the download link for the jar and before you download it, please note that you cannot win against the computer  . https://www.dropbox.com/s/voc7obrlqctgxda/tictactoe.jarHere's some details about the game. I recently learnt Scala and wanted to implement the AI completely in Scala. For this I first created a simple text based game in Java with the move recommender engine in Scala. Once the text game worked fine, I used Slick to create the game and Inkscape to create the (lame) graphics. There is a standard strategy for TicTacToe as given on Wikipedia. But I wanted to come up with my own strategy for it. So I didn't bother to look at this link until far later when my AI wasn't performing optimally. I've developed a recursive score based AI which calculates all possible moves and assigns a score to every possible move. But this method led me to 3 issues - viz incorrect handling of 1. forks 2. immediate wins 3. immediate losses So, I've had to adapt a bit of the standard strategy to fix these issues. Forks were handled through hardcoding. In any case, I've cut corners everywhere in this project. The code is an unmaintainable mess with hardcoded strings, numbers and pixel locations. But there are far better tictactoe implementations out there, so I didn't want to make too much of it. It's more or less a Proof of Concept. I'm happy to have been able to integrate Java, Slick and Scala. Btw, creating the jar has been a nightmare. Thanks to jarsplice, I was finally able to make it. The complete instructions on how I did it are here: http://stackoverflow.com/questions/13527869/could-not-find-main-method-from-given-launch-configuration-when-using-javasca
|
|
|
|
Gjallar
|
 |
«
Reply #1 - Posted
2012-11-23 13:15:30 » |
|
Oh me oh my, that is one big-ass jar file for such a small game. I looked into the file and I'm pretty sure the "slick.zip" is not necessary, so that's 10 Mb less already. Besides that it's pretty good for a first game, with sounds and all. No bugs discovered 
|
|
|
|
plastygrove
|
 |
«
Reply #2 - Posted
2012-11-23 13:27:36 » |
|
I looked into the file and I'm pretty sure the "slick.zip" is not necessary, so that's 10 Mb less already. Besides that it's pretty good for a first game, with sounds and all. Not bugs discovered  Thanks for that. I removed slick.zip and now the .jar is ~10mb. Again, bulk of the file is because of the scala library which is taking up ~17mb uncompressed. Thanks for trying out the game. I'm glad it worked, I didn't test it on any machine other than mine.
|
|
|
|
Games published by our own members! Check 'em out!
|
|
Jimmt
|
 |
«
Reply #3 - Posted
2012-11-23 17:23:55 » |
|
lol, 10 mb is still huge for a tic tac toe game...everything on java4k is under 4 kilobytes and a lot more complex. Although I understand Scala is added. Nice little game tho, keep on getting draws 
|
|
|
|
plastygrove
|
 |
«
Reply #4 - Posted
2012-11-23 18:39:06 » |
|
lol, 10 mb is still huge for a tic tac toe game...everything on java4k is under 4 kilobytes and a lot more complex. Although I understand Scala is added. Nice little game tho, keep on getting draws  Well, I didn't say it was an efficient game  . It was a good learning exercise on integrating Scala with Java. The algo I'm using is also probly not the most optimal either as you can see from the slight delay in playing the first move. Thanks for trying it out. I was thinking of offering a prize for anyone who beats the computer  . Because, if you can beat the computer, it's probly a bug!
|
|
|
|
|
Riven
|
 |
«
Reply #6 - Posted
2012-12-01 01:01:33 » |
|
1 2 3 4 5 6 7
| - var result = if(a == b) true else false + var result = (a == b)
- if(a == b) result = true - else result = false + var result = (a == b) |
or... is this oddness mandatory in Scala?
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings!
|
|
|
masteryoom
|
 |
«
Reply #7 - Posted
2012-12-01 02:16:18 » |
|
I would really like it if you could make the computer beatable. 
|
|
|
|
actual
|
 |
«
Reply #8 - Posted
2012-12-01 03:27:33 » |
|
or... is this oddness mandatory in Scala?
Nope, you're versions are valid Scala.
|
|
|
|
plastygrove
|
 |
«
Reply #9 - Posted
2012-12-01 03:28:20 » |
|
Well, the AI code in Scala for me takes ~130 lines. And there's also a support file written in Java, so definitely not as compact.  or... is this oddness mandatory in Scala?
Ha ha, no you're right. I do that myself quite often, it's the curse of imperative programmers in the functional world  I would really like it if you could make the computer beatable.  Nothing easier, I'll just make the computer play a random move everytime  . Or to make it a definite loser, I'll implement a method avoid3InARow() 
|
|
|
|
Games published by our own members! Check 'em out!
|
|
sproingie
|
 |
«
Reply #10 - Posted
2012-12-01 04:09:54 » |
|
Good to know jarsplice worked, but if you use sbt, the one-jar plugin works very well. The sbt-assembly plugin is also good for making fat jars but I don't think it has a story for native libs.
|
|
|
|
plastygrove
|
 |
«
Reply #11 - Posted
2012-12-01 05:17:33 » |
|
Good to know jarsplice worked, but if you use sbt, the one-jar plugin works very well. The sbt-assembly plugin is also good for making fat jars but I don't think it has a story for native libs. I would really like to use SBT, but it's just not convenient if you're using Eclipse. Doable definitely, but not convenient. After racking my brains for a few hours to make a jar, jarsplice was the only thing that worked for this project. I don't understand why it's so difficult to make a jar using Eclipse. They've got all the wizards, they just don't work well if you use external libs
|
|
|
|
sproingie
|
 |
«
Reply #12 - Posted
2012-12-01 06:43:31 » |
|
sbt and eclipse work great together: 1
| addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0") |
Stick that in ~/.sbt/plugins/eclipse.sbt then "sbt eclipse" should work for any project to generate eclipse project files. I've always found IDE export wizards to be way more cumbersome than they're worth.
|
|
|
|
plastygrove
|
 |
«
Reply #13 - Posted
2012-12-01 07:23:19 » |
|
sbt and eclipse work great together: 1
| addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0") |
Yup, I use the eclipse sbt plugin now and then. I normally put it in a folder called 'project' in the project folder itself, but your method seems more convenient. It works especially well with libraries on the repository like Akka, but not sure how to get it setup with a project using Java and Slick2D, or for that matter, libraries on my PC. Also not sure what the workflow should be like if I need to add more libraries at a later time. Do I run sbt and re-import or should I do it in Eclipse itself? I'll need to learn a bit more about build.sbt as well.
|
|
|
|
sproingie
|
 |
«
Reply #14 - Posted
2012-12-01 22:04:41 » |
|
Since the current slick isn't in maven anymore, it's hard to make it a managed dependency, but any jar you stick in the lib/ folder will be picked up by sbt. However, it's likely sbteclipse will only automatically add managed deps, so you'll have to add them in your project in eclipse by hand. Maybe these days it adds a folder classpath container for lib/ but I've never tested that.
Oh and I believe sbt also adds lib/ to your native library path as well, so 'sbt run' shouldn't need any special setup to pick up the native libs. It's still your job to make it work outside of sbt though, at which time there's jarsplice or one-jar (one-jar will use everything in /binlib as a native dep). If jarsplice has an API or CLI front end, maybe I could look into writing a sbt plugin for it.
|
|
|
|
|
souldown
Innocent Bystander
|
 |
«
Reply #16 - Posted
2012-12-04 07:53:52 » |
|
I have just finished my fist game too! Its also tic tac toe. All written in java with no scala or anything else. Also mines 2 player and haven't set about working on a 1 player version of the game yet. Will do that eventually. Also mine doesn't seem as pretty as yours. (shocking as that might be to you!)
|
|
|
|
plastygrove
|
 |
«
Reply #17 - Posted
2012-12-05 05:32:40 » |
|
I have just finished my fist game too! Its also tic tac toe. All written in java with no scala or anything else. Also mines 2 player and haven't set about working on a 1 player version of the game yet. Will do that eventually. Also mine doesn't seem as pretty as yours. (shocking as that might be to you!)
Hey, welcome to the forum. Take it from one who has just completed a tic tac toe game, I know the first game is anything but trivial. See if you can get it to a 1-player version. The strategy is quite simple as given on wikipedia but implementing it is definitely not easy.
|
|
|
|
Hagex
Junior Newbie
|
 |
«
Reply #18 - Posted
2013-01-07 10:25:51 » |
|
Awesome game!I love how there is absolutely no delay between the time when the player plays and when the computer plays! I have yet to win a game though 
|
|
|
|
plastygrove
|
 |
«
Reply #19 - Posted
2013-01-08 02:31:38 » |
|
Awesome game!I love how there is absolutely no delay between the time when the player plays and when the computer plays! I have yet to win a game though  Glad you liked it!  Yes, I did consider putting in a delay, but felt it was unnecessary. This is tic tac toe and not chess  . I wanted the game to be as quick as possible so that you can play as many times as you like with min time wasted
|
|
|
|
JohnsonCorp
Senior Newbie 
|
 |
«
Reply #20 - Posted
2013-01-21 06:12:10 » |
|
Feels like AI is cheating or something. Is it possible to win?
|
|
|
|
sproingie
|
 |
«
Reply #21 - Posted
2013-01-21 06:20:24 » |
|
Feels like AI is cheating or something. Is it possible to win?
That either deserves applause or a facepalm, not sure which. 
|
|
|
|
plastygrove
|
 |
«
Reply #22 - Posted
2013-01-21 17:52:29 » |
|
Feels like AI is cheating or something. Is it possible to win?
Nope, like I said, AI can never lose. If it loses (or cheats) then there's a bug  . That either deserves applause or a facepalm, not sure which.  Heh, I agree with you 
|
|
|
|
ra4king
|
 |
«
Reply #23 - Posted
2013-01-25 00:37:04 » |
|
Feels like AI is cheating or something. Is it possible to win?
That either deserves applause or a facepalm, not sure which.  Considering his other high quality comments, I'm pretty sure it's the second.... 
|
|
|
|
|