![]() |
|
Online Connect Four |
Michael Jensen
Member #2,870
October 2002
![]() |
My friends and I have been playing connect-4 a lot, and so I whipped up a quick and sloppy site to play it on -- it's all in ajax so everything's automagic (not like chessnuts was, if you remember it) -- but the code is pretty sloppy. It renders fine on Firefox and IE 7. Haven't tested anything else just yet. You need frames, javascript, and session cookies enabled to use it. Here's the link: http://mjmtest.no-ip.org/connect4/ There is no one player mode, you'll have to create a game and wait for a joiner, or if anyone else is on, join theirs. There's a 30 second timeout, and it's not very low-speed friendly. Also if you have metered bandwidth, don't bother, it'll just run up your bills. (Remember: I made this quickly and sloppily.) Feel free to use the site, just don't try to hack anything please. (I haven't even bothered with security, and what's worse, it's hosted on my development server... but it's safe for the clients.)
|
benthx
Member #8,872
July 2007
|
Been playing this against the computer. Played many years ago in YMCA hostel in california. After a few games against friends etc.... I realise how much I liked it. Kids games yes but played with much stategy. Want to see how I can play online against someone around the world. Thanks |
LennyLen
Member #5,313
December 2004
![]() |
It appears to work properly on Opera (v9.22). I was able to join a game, but the creator isn't responding, so I don't know if the playing part works (I assume it does since everything else does). I noticed that if you quit a game that you've joined it counts it as a loss. While this makes sense in normal circumstances, I think it would be better if it counted as neither a loss nor a win if you quit before a single move is made, or if the other player hasn't responded with a certain time frame.
|
Mars
Member #971
February 2001
![]() |
Sorry, that was me. I left the game open and continued to do other stuff in the other tabs, then forgot about it... I'd still like to try it though. -- |
Michael Jensen
Member #2,870
October 2002
![]() |
As for the game: I'll be leaving the server running, so have fun; I might optimize the game for low bandwidth at some point. Glad to hear it mostly works on opera. Quote: I think it would be better if it counted as neither a loss nor a win It's not logged anywhere, so it doesn't really "count". The evilest thing ever my gf did to me: I added a /me switch, and she typed "/me has left the game" -- so I quit too and was like "what's up?" but she was still in the game, me leaving was a forfeit! that sneak! -- In the future you can tell if someone really left or not, because if the game is not over, it will announce the winner when it announces them leaving the game!
|
CGamesPlay
Member #2,559
July 2002
![]() |
It sends about 3 AJAX requests per second. -- Ryan Patterson - <http://cgamesplay.com/> |
Slartibartfast
Member #8,789
June 2007
![]() |
Tried it right now but nobody was on. :S The good side is that it reminded me that I planned to program a variant of connect four that me and my friends like to play a lot. ---- |
Johan Halmén
Member #1,550
September 2001
|
I just played against myself. I opened one window in Safari and another in Firefox (went a bit schizo). It seemed to work quite well, although I lost ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. |
Michael Jensen
Member #2,870
October 2002
![]() |
Quote: It sends about 3 AJAX requests per second. Should be more like 5 to 10 depending on what window/etc you're in. But yeah, don't play it on a modem or on metered bandwidth. Quote: while Firefox only showed the "Updating..." text in that window. That's strange, what version of firefox are you using? It works great in all the firefoxes I've tried it on (Though I think they were all 2.0 at least) IP address has nothing to do with how it tracks your identity -- I did most of the testing on a single computer by flipping between IE7 and Firefox 2.
|
Johan Halmén
Member #1,550
September 2001
|
The About box said: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; fi; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3 I guess it was all just about lagging net. Sometimes when I click at any link (like "Add reply") nothing happens, the blue process bar on the address line stops at the beginning, no error message appears ever. A new click gets it rolling again. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. |
Michael Jensen
Member #2,870
October 2002
![]() |
Hmmm, If it's anything I bet it's network traffic. I wonder why it would do that though. Clicking send forces a network update, while normally it's supposed to update the chat about 3 times a second without any activity. (That's just the chat though, lots of other things on the page update themselves too.)
|
CGamesPlay
Member #2,559
July 2002
![]() |
You really need to fix that. You should chunk multiple requests into one, and should only have one pending request at a time. Just FYI, the HTTP spec recommends (requires?) that only 2 simultaneous requests to a single server happen at once. This may be the reason that your requests aren't going through. Updating the chat once per second should be sufficient. No one will be able to tell that there is delay, they will simply perceive that the other users haven't said anything yet. -- Ryan Patterson - <http://cgamesplay.com/> |
Michael Jensen
Member #2,870
October 2002
![]() |
I'll think about it -- it just seems less responsive to me at once a second; Edit: I'm more concerned with trimming down the network traffic that each hit gets than with how often it hits.
|
CGamesPlay
Member #2,559
July 2002
![]() |
Quote: Edit: I'm more concerned with trimming down the network traffic that each hit gets than with how often it hits. Here's some fun trivia:
You realize that each request's HTTP headers are several times larger than the actual data you're sending? To trim down your network traffic, reduce the number of requests you send. You can't make your requests any smaller. Oh and it seems like each of those requests is generating a javascript error for me. [append] Also, you waste bandwidth by sending HTML instead of JSON. ASP.NET AJAX Enhancements will allow you to automate the task of generating an XmlHttpRequest and will serialize the data as JSON. You may want to look into that. Finally, there's absolutely no need to send the whole user list more than once. You should instead send the list of users who have connected and disconnected. -- Ryan Patterson - <http://cgamesplay.com/> |
Michael Jensen
Member #2,870
October 2002
![]() |
That one is not a very good example, and that one I believe is only requested once a second and there was only one person logged in (what if there was 200?). There are requests that if there were a lot of traffic on the server would be several KB of data. For instance the chat window, instead of sending only new data, sends everything that's transpired in the last four hours. (It was a quick hack) -- I'd like to fix that first. But yeah, if it's really a big deal, when I get home tonight, I can upperize those delays. Quote: Also, you waste bandwidth by sending HTML instead of JSON. First off, I'm not using asp.net ajax, this was all a quick hack. Secondly Yeah I know, hence like I said above, I'd like to trim down the volume of data it sends as opposed to how often it is sent. Quote: You should instead send the list of users who have connected and disconnected. I know. I'm just not. It was easier to write, and I might fix it someday. Hell it would be better if I just sent one packet of data to the client that had all of the changes since their last packet of data -- users, chat, etc. This is my main priority for changes on this project -- if I'm ever motivated to work on it. Quote: Oh and it seems like each of those requests is generating a javascript error for me. I don't get any in firefox... what browser/version are you using?
|
CGamesPlay
Member #2,559
July 2002
![]() |
Quote: That one is not a very good example, and that one I believe is only requested once a second and there was only one person logged in (what if there was 200?). Then you would still be transferring 200 users more per second than what you need to. I picked it because it was the request that came up the most in Firebug's log. It doesn't really matter which request you use, as they all have all that HTTP overhead. Quote: I don't get any in firefox... what browser/version are you using? It was odd. My browser slowed to a crawl while I was writing my post with your site open. I closed the site and firebug, from this tab, started counting errors. It counted several hundred in total. The way this should really work is like this:
By using this method, you can cut your requests down by a factor of the number of different scripts you have (you will only be querying one script from XHR). Also, you'll be saving the redundant data you transfer by sending the whole user list, and you'll also be saving the overhead of transferring HTML. It's more code, but it's The Right Way -- Ryan Patterson - <http://cgamesplay.com/> |
Michael Jensen
Member #2,870
October 2002
![]() |
Quote: Subsequent XHRs should receive changes since the last one Umm this is exactly what I just suggested... You just send all the data on the page's first load, and then only send changes. Yeah, it's the right way. But like I said, this was a quick hack (Something like ~six hours of coding) and if I use it enough, I might invest some time rewriting it. As for now: it works, (and it's fast on all of the foreign machine's I've tested it on) and yeah I'll get around to fixing the couple of bugs, but I'm not motivated enough to completely rewrite the game's protocol at the moment.
|
CGamesPlay
Member #2,559
July 2002
![]() |
I'm sorry, this was all I saw. But if you know the right way to do it then it's okay Quote: For instance the chat window, instead of sending only new data, sends everything that's transpired in the last four hours. (It was a quick hack) -- I'd like to fix that first. But yeah, if it's really a big deal, when I get home tonight, I can upperize those delays.
-- Ryan Patterson - <http://cgamesplay.com/> |
Michael Jensen
Member #2,870
October 2002
![]() |
Yeah, it's just a matter of me being lazy. If I do a serious site or anything for a customer it wouldn't be this horrible. I upped the delays somewhat.
|
|