Just over 2k lines. For this?

Pages: 12
Tic Tac Toe (yay?)

Somewhat good looking and a fun AI to play against (you'll win if you pay attention)

Tell me what you think! (if you feel like playing tic-tac-toe that is)

download link:
http://ifile.it/sjtyeqo

(For the less adventurous : Screenshots)
http://imgur.com/MPz6o.png
http://imgur.com/DResk.png
http://imgur.com/d4woz.png

whoo, I love finishing stuff =]


Last edited on
you made a tic tac toe in 2k lines?
Werd
Triple Triad anyone? Looks nice...but I don't really feel like downloading it. XD
2k? I would have thought tic tac toe required less.
2k?

A badly written, copy-pasted like hell, Scala code is only ~200 lines (and it can be easily refactored down to 100):
http://technotes-himanshu.blogspot.com/2010/01/unbeatable-tic-tac-toe-in-scala.html

I would not expect a good C++ implementation using STL to be more than 5x longer (instead of 20x).
Last edited on
@rapidcoder
The Scala variant has no GUI, which almost always burns a lot of code lines.
Still, I'm tempted to rewrite it using less lines and making it a stand-alone executable. Although I don't quite get what all the wizard resources are for... are they actually used in the application?

Edit: @ultifinitus
By the way, you'll do yourself a great favor if you update to the latest Code::Blocks nightly. The improved code completion and calltips are indispensable.
Last edited on
Well, I suppose it largely depends on the GUI - what exactly is used here?
So what did you use for the GUI? It runs on linux too, so it's a good choice ;) Appears to redraw the screen a bit too often however.

As for the scala thing: being on ubuntu, I typed sudo apt-get install scala and got the thing installed. However, I couldn't make your code run - I can't seem to tell scala how to compile it (and since it looks like a form of Java, I expect it to be user friendly -> pokes at rapidcoder).

btw here is project I am working on at the moment - a small (50 frames, 5 seconds) 4-D animation in C++ done with wxWidgets (it is actually n-D for 2<=n<=8 if you change the letter input to be "B" in one of the dropboxes and the dimension in the other dropbox). You also have to click the "Go" button :)

https://sourceforge.net/projects/vectorpartition/files/RootSystemAnimation.zip/download

The animation draws something called a "root system" - it doesn't matter what it is, just it looks cool :)
Last edited on
I wrote a minesweeper-clone in C++ using Qt in a day at work once. I think it was around 400 lines but it was written well. 2000 lines sounds like a novice attempt. (No offense meant by this.)
I'm currently writing a concurrent pong clone. Currently I'm figuring out how the programs will decide who renders the ball. I'll either have one of them always render it, have ball-rendering-duties change hands depending on which half of the screen its in, or have ball-rendering-duties change hands every time a player touches the ball or it goes off screen. The hardest part will be getting them both to render to the same window. I want to do it without having a third process control it, but I don't think it will work...
Shouldn't the concurrency part be solely on synchronizing the model between the two players? If there is only a single target to be rendered to then there should a renderer independent of either side, and if there are two render targets meaning each of the player plays on a different computer, then rendering should also be done independently... or am I missing something?

I would think it would kinda be like this...


                         Renderer

                          ^  
                          || read-only
                          ||
       write-only                       write-only
Player1=====>         Model         <=====Player2

Last edited on
Kinda off-topic, but render the background first using multiple threads, then draw the ball and everything else (after the background threads are all finished).
Besides, have you confirmed this approach results in a performance gain? This kind of thing is typically limited by memory throughput, so using multiple threads is likely not much faster or even significantly slower.

Edit: that's assuming you're trying to speed up rendering using multi-threading. If not, disregard this post.
Last edited on
@hanst99
Yeah, you're right actually, I will write a renderer.
[Edit] I don't think that that model will quite work. If the two players can't read the pipe then (a) neither knows if it is winning and (b) neither knows where the ball is. Both of those problems are solved if the players have read/write acces though.

@Athar,
I'm not bothered about speed, I'm doing it for the sake of it.
Last edited on
Sorry for the late reply, been working!

Now as for the 2k lines, that's including my engine, which has

Image loading
Animation loading
Custom events
Text handling
Collision det/res
Image/Font managers
Networking
AI

The actual code for the game has just under 100 lines.

The GUI uses SDL for everything.


Athar wrote:
By the way, you'll do yourself a great favor if you update to the latest Code::Blocks nightly. The improved code completion and calltips are indispensable.

Yes, I should, haven't taken the time to do so lately, my linux box does have the latest nightly, but windows does not.

@tition: I'll take a look at your project, sound interesting.

moorecm wrote:
I wrote a minesweeper-clone in C++ using Qt in a day at work once. I think it was around 400 lines but it was written well. 2000 lines sounds like a novice attempt. (No offense meant by this.)


The code took around 1h-2h, graphics 45m. The code is solid.

chrisname wrote:
I want to do it without having a third process control it


Why don't you want a third process/thread? Simply applying the ball wouldn't take much additional power, though communication could be ... fun =]
@ultifinitus,
I wanted to have each node render its own stuff, but I can't see that being a possibility so I'm using a third process as a renderer.

@* (mostly hanst99)
This is how it is going to work:
Key:
	[1] -- pnode (player node) 1
	[2] -- pnode (player node) 2
	[r] -- rnode (render node)
	r   -- read access
	w   -- write access
	r/w -- read/write access

             [r]
             r/w
              ^
              |
              |
              |
              v
[1]<---------<+>---------->[2]
r/w                        r/w


1. [1] & [2] send events across the network (move_up/move_down/get_ball_xy/get_my_xy)
2. [r] reads all messages containing [1] or [2] and processes them for events
3. [r] sends information back to [1] & [2] ([*]_xy/[1]_xy/[2]_xy/[*]_exit)
4. [1] & [2] process messages containing their player number ([1] or [2]) or [*]
5. Unless [*]_exit has been sent, goto 1


Sorry to steal your thread, ultifinitus. I'll stop it now :)
Last edited on
Awww...
http://imageshack.us/photo/my-images/714/failurey.png/

Who needs .exe's anyways?
@ascii
lol, I can give you code if you want =]

Sorry to steal your thread, ultifinitus. I'll stop it now :)

No worries. Life is always good.
@ascii
You can still run it as long as Wine is installed.

As for the scala thing: being on ubuntu, I typed sudo apt-get install scala and got the thing installed. However, I couldn't make your code run - I can't seem to tell scala how to compile it (and since it looks like a form of Java, I expect it to be user friendly -> pokes at rapidcoder)


Should just run in REPL fine, but I haven't tried. That code is really also a novice attempt (too much copy-paste) and quite dated. The author says it is compatible with 2.7 version, while the current one is 2.9, which is not 100% source-code compatible with 2.7 (2.7 -> 2.8 slightly broke compatibility because of new collection design - not a serious thing, but sometimes you have to fix a thing or two per 1k lines). So, there might be some compatibility problems.

As for GUI, if your code needs 1.5k LOC just for a tic-tac-toe GUI, this means you should change your GUI toolkit (or start using one).
He said the 2k lines include his engine.
Pages: 12