Allegro.cc - Online Community

Allegro.cc Forums » The Depot » [Community Project] AMGC2

This thread is locked; no one can reply to it. rss feed Print
[Community Project] AMGC2
Indeterminatus
Member #737
November 2000
avatar

What about a simple chess game?

_______________________________
Indeterminatus. [Atomic Butcher]
si tacuisses, philosophus mansisses

Evert
Member #794
November 2000
avatar

Already suggested.
I just need the time to (slightly) trim my chess programme and make it work with the display framework - which should be easy enough, since the entire programme apart from the one sourcefile that displays the board is independent of Allegro.

Indeterminatus
Member #737
November 2000
avatar

Evert said:

Already suggested.

Sorry, I must have missed that. Anyway, I'm looking forward to it :)

_______________________________
Indeterminatus. [Atomic Butcher]
si tacuisses, philosophus mansisses

miran
Member #2,407
June 2002

Quote:

Miran, if you are serious about the network play, I have two turn-based multiplayer games that I could port to the AMGC2 model (they are Magic Maze and Hexagon, from my site). I don't have any expertise to offer on how to implement the server etc. but these two games will be useful to have something for testing. And I'll help with testing, of course.

Yes, all entries are welcome. Eventually changes will be made to the IGame interface to allow network games to be developed, but that shouldn't stop you from making a game that will work without network support which can be added with little effort later.

Quote:

Are you aiming only at turn-based games? I recommend you do. Lag will be less of an issue, and it would be more feasible to have a single server that suits the needs from all allegroids all over the world. For real time games that would be impossible, and you'd end up with many regional servers with too few people logging in to make it interesting.

Yes, right now the focus is on turn based games like chess and turn based strategies. I wouldn't mind having a system capable of handling simple action games as well but that's not a priority.

Btw, I'm not working on the hardcore network code myself. There's a secret contributor in this project who wants to remain anonymous for the time being, at least I assume so, otherwise he would have already posted in this thread. ;D

Oh and with the whole weekend in front of us I hope to get some serious work done in the next 48 hours or so. ;)

--
sig used to be here

Audric
Member #907
January 2001

Suggestion: generic Load / Save buttons? Not sure, because realistically, I don't expect many people will code games which require those. I suggest it anyway because the framework allows to unify their look-and-feel as well: Generic "Save" / "Load" windows with 10 slots, calling virtual Save(FILE *) and Load(FILE *) methods, plus a Save_query() returning false if 'this is not the right moment to save')

Miran, if you succeed in bringing netplay into reality, this will be tremendous achievement as a learning tool for programmers. In my opinion, it's already a very good introduction to OO programming, as it's one of the very few examples I've seen, where derived functions show a purpose. It also teaches the programmer to separate display from logic, and store his current-game-in-progress-info in one place... Useful habits.

I'm really eager to be able to write a Logic() function which first 'checks the inbox' for the messages which arrived since last update.

Turn-based would still be the easiest to program, but even "action" games based on 1-second units would still be very playable, like for example a 2-player Dungeon Master / Roguelike. Such games should implement the my-turn / your-turn system, except each game sends a no_action message when a time_out is reached. (This is to ensure the 2 players won't collide)
Better if the game can "stack" input actions, though : Like, you click on a destination tile, and the game takes care to send at regular intervals the individual messages "up", "up", "right", "up" etc.

miran
Member #2,407
June 2002

About the load/save functions... that would be very easy to implement for me. But on the other hand, if a game requires those functions, it's probably not a "minigame", although for games like your Blocks it would be useful. Btw, I played your game quite a bit. Couldn't get past level 40 for some reason. There's more than half hour of gameplay in there, although the first levels really are very easy... :)

Umperio said:

Fixed small issues and so version 0.4

Did you forget to put the source in the zip? I don't mean to say that you have to release the source, but those of us who are in Linux really can't play the game :)

--
sig used to be here

Ilyas Salman
Member #6,762
January 2006
avatar

I present my first game with allegro:
World Pong

It's a little ping pong game with strike feature: When your bat moves and the ball collides, the ball's direction is manipulated by the bat's direction.

Now, I'll work for the basic .exe program of the same game.

Screenshot=attachment.

The game is 1 Mb (compressed), because the background (bmp), made with mapgen 1.1.
Downloadlink:http://rapidshare.de/files/13007720/worldpong.rar.html

miran
Member #2,407
June 2002

I appreciate the effort :) but there are a few things I found wrong with your game:

- It doesn't work. The ball constantly travels only along the top edge of the screen and when you try to hit it, it gets stuck until you move the paddle away. (see attached screenshot)

- At 1MB it hardly qualifies as a minigame (just like my dart game :P). But that's no problem really. What bothers me is that the background bitmap adds nothing to the gameplay while weighing almost 1MB. You could save the background as jpg and use the jpeg Allegro add-on to load it. You'd have to install/release it in your game of course.

- There's no source. Luckily I'm in Windows right now so I could play it, but most times I'm in Linux (as are quite a few other people) so I really would need the source.

--
sig used to be here

umperio
Member #3,474
April 2003
avatar

Oops I just forgot about it, I'm really sorry. I reuploaded the complete package. You have to forgive me, I'm still a linux beginner :P

Evert
Member #794
November 2000
avatar

Ok, I've hacked my (old) chess-programme into working with the interface. I didn't have to touch the actual chess-code at all, which was good (I wrote it with that in mind). The only thing I've disabled is the `ponder' feature: allowing the computer to think while you are thinking. To get it working, uncomment a few lines and compile the source again with pthreads enabled.

The interface itself is a pretty ugly hack though: I copied most of the code from my original quickly hacked-together interface and beat it until it compiled and worked. This means that right now you cannot change any settings (such as the maximum searchdepth and how long the computer thinks; these are hardcoded at 12 ply and 10 seconds). Worse, it bypasses the interface's input method, which means that you don't get keyboard shortcuts, which means that you also cannot take back any moves.
The biggest problem, however, is that nothing updates while the computer is thinking - the logic callback just freezes for ten seconds while the computer is thinking. That means that the game will appear to hang, while it actually doesn't. I'm not sure what to do about that right now; personally I'm not sure if the framework as it is (ie, a logic loop and a drawing loop that each update N times per second) is well suited for a game like chess. I could add a callback function that is called by the programme to get it to print some output, but that also doesn't play nice with the framework's separation of logic and drawing. Spawning a separate thread in which the computer thinks would be an option, but it again requires pthreads.
Anyway, the game is playable and I'll see if and when I can be bothered to improve the interface. ;)

I remember that there were a few things that I wanted to clean up and implement in the chess programme itself (mainly having to do with move generation and move ordering in the generator), but the current programme at works.

EDIT: as for compiling, just unpack the code and run `make'. That should build it correctly for either Windows or *nix, but I haven't actually tried it in Windows.

miran
Member #2,407
June 2002

Looks great :) Maybe you could do the "thinking in background" thing like this:

- in the logic function set a flag
- if the flag is set, run the thinking function for a while; the thinking function should check the time every now and then to see when it should stop and then continue from there the next time it is run
- once the thinking function has been run for 10 seconds (1000 times at 100 LPS), reset the flag to stop thinking

That is if the thinking function has a loop that can be interupted and then continued like that...

Btw, on Windows I had to change the makefile so it runs g++ instead of gcc...

--
sig used to be here

Fladimir da Gorf
Member #1,565
October 2001
avatar

Quote:

Probably no. Besides, OpenLayer doesn't work on Linux. At least not on mine...

You mean, OpenLayer 2.0 doesn't compile because the compiler doesn't understand a function definition? The CVS version compiles for Linux as well. OpenLayer is not platform specific in any single way... That's why it uses supporting libraries which are cross platform.

OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori)

Evert
Member #794
November 2000
avatar

Quote:

That is if the thinking function has a loop that can be interupted and then continued like that...

That's the thing. It can't; at least not easily.

The computer uses the mini-max algorithm (in the form of alpha-beta, for those who want to know) to generate a score for each move in the current position. It does this first for one ply, then for two ply... etc., until the maximum searchdepth has been reached, or the time expires (whichever comes first).
It would be relatively easy to interrupt this at the root of the tree (so outside of alpha-beta) and continue from there, but alpha-beta itself is a recursive function and not very easy to interrupt. It could be rewritten as in an iterative formulation, of course, but that's a bit more trouble than I care to put into it. I also don't want to put too many checks in the code because I don't want to slow it down unnescessarily (the playing engine is completely separate from the interface, and I'd like to continue developing it separately).

I'll see if I can easily get it to work using a separate thread. It shouldn't be too difficult, I think.

miran
Member #2,407
June 2002

Quote:

You mean, OpenLayer 2.0 doesn't compile because the compiler doesn't understand a function definition? The CVS version compiles for Linux as well. OpenLayer is not platform specific in any single way... That's why it uses supporting libraries which are cross platform.

I mean it requires GlyphKeeper which requires FreeType 2.1.10 while I have 2.1.9 and upgrading apparently involves having to use some form of black magic.

Quote:

I'll see if I can easily get it to work using a separate thread. It shouldn't be too difficult, I think.

Yeah, that would be best, I think...

--
sig used to be here

amarillion
Member #940
January 2001
avatar

Attached: v0.95 of the Pacman minigame.

Changes since v0.90
- vastly optimized draw speed, removed all the redundant buffering
- there is now more than one level, i.e. the game doesn't stop after you finish the first level
- cleaned up code a lot
- added short pauses before a level starts, after you die, etc.
- fixed bug in collission detection code.
- scared ghosts blink a while before returning to normal state

I haven't had any hangs or crashes in a while now, the responsible bug must have been silently fixed while cleaning up the code. If you find otherwise, please let me know.

miran
Member #2,407
June 2002

Excellent. Doesn't hang anymore... :)

--
sig used to be here

Fladimir da Gorf
Member #1,565
October 2001
avatar

Quote:

I mean it requires GlyphKeeper which requires FreeType 2.1.10 while I have 2.1.9 and upgrading apparently involves having to use some form of black magic.

You could of course compile it with -DOL_NO_TTF and use an another way to render text... But it's true that then other's OL code might not work for you if it uses the text routines :-/

OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori)

Audric
Member #907
January 2001

1) I'm a bit worried by the way settings are handled.
load_settings() WRITES in the structure, so using a static structure for this
is a bit messy IMO. (it's shared by all the users of the DLL)

In my game, I malloc a fresh GameSettings structure in the creator of my
IGame class and feed it default values, then free it in the destructor.
I was counting on GameDriver::Run() to run load_settings() on it and feed the
current values from .cfg, but it reveals a bug in this function : it calls
load_settings(settings, encode_game_name(theGame->GetName()));
This reads from a file called "<gamename>" with no extension, in the current
directory, instead of "<whatever_directory>/<gamename>.cfg"
(I've tested, it really behaves this way)

Actually, if settings usually work OK today, it's a friggin miracle, as I can't
see WHERE load_settings() is called with the right parameters outside of
SettingsDlg::Popup() - this one is supposedly only called when that
window opens ???

Anyway, this probably explains why the settings randomly disappeared sometimes,
very annoying in my game as this records your progress.

2) I found a memory leak, but it's unrelated: the IGame created in
MainMenu::OnSettings() is not deleted when the Settings window closes.
SettingsDlg::~SettingsDlg() may be the right place to fix it, I suppose.

3) During 'pause' (ESC), the keys[] array is freshly allocated and
uninitialized, containing random junk : this gives a crazy behaviour if the
Logic() function reads from this array - In my game, the blockman was running
right while pushing neighbor crates up and down...
Maybe better to init all keys as 0...

4) About network: I realize I will probably never code a network game if I can't
test it. Excuse me if I'm Mondaydreaming, but I guess the only platfom which
would allow a hobby game programmer like me to code a network game, is an
engine which could handle network AND it's "emulation": Being able to run the
same code either with actual networking between 2 computers , or as 2 programs
on the same computer.
I can install 2 Ethernet cards if it requires 2 different IP addresses, but the
engine still needs to be cleanly multi-user : no "accidental" sharing of static
data, because this could make the program behave differently than on 2
computers.

Evert
Member #794
November 2000
avatar

Quote:

4) About network: I realize I will probably never code a network game if I can't
test it. Excuse me if I'm Mondaydreaming, but I guess the only platfom which
would allow a hobby game programmer like me to code a network game, is an
engine which could handle network AND it's "emulation": Being able to run the
same code either with actual networking between 2 computers , or as 2 programs
on the same computer.

Run the server and the client on the same machine and have the client connect to localhost (127.0.0.1). No emulation required.

Seppl
Member #4,656
May 2004
avatar

[offtopic]

Quote:

Run the server and the client on the same machine and have the client connect to localhost (127.0.0.1). No emulation required.

well... some time ago I was programming a network game using localhost to test it and when I wanted to test it via LAN, it simply did not function and i couldn't figure out why...

I borrowed a second computer so i could test it at frequent intervals via LAN and rewrote the whole thing and now it's working...

Just to say that I have made some bad experience using localhost...
[/offtopic]

__________________________________
All you need is lunch - The Rutles

amarillion
Member #940
January 2001
avatar

Quote:

Run the server and the client on the same machine and have the client connect to localhost (127.0.0.1). No emulation required.

This is exactly what I suggested before, IMHO the way to go. No need to have extra ethernet cards.

Granted, this is not the real life situation with all the extra headaches of dealing with lag, lost connections, etc. But it would be good enough to help test and develop the games themselves.

miran
Member #2,407
June 2002

Audric: Thanks for the bug reports! :D

1. You must be looking at an old version of the source because I already fixed that in 2.08.

2. It is indeed a memory leak and easy to fix. Thanks.

3. Same as 2.

4. Network code is being worked. Once there is sufficient progress, the API and the server will be released. You will then be able to setup a development configuration, be it on one computer (using localhost), a small network or any other way you can. There will also be at least one public server.

--
sig used to be here

Audric
Member #907
January 2001

miran said:

1. You must be looking at an old version of the source because I already fixed that in 2.08.

Arrrggghhhhh this took the best part of Sunday for me to make sense, it was making me crazy.

The other problem in pause mode was seen only before 2.7 indeed, since it forced me to implement a "paused" flag, I couldn't see if it was still there afterwards.

Network: The way I understand it, the central "public server" is for taking care of the chat room &| list of active servers.
ie for this part:
It would be for example a no-display amgc2-host.exe on Miran's home (or anywhere :)), listening on xxx.xxx.xxx.xxx:xxxx

When you start a Pong server however, it should do 2 things at the same time:
start listening on one IP:port for clients, and keep polling the central server every 10 seconds with the message 'I am a Pong v1.5 server on IP:port, hosted by Audric, 1/2 players'

Clients connecting to the central server would only query it for list of open game servers, which would list the servers which have not timed out.
Clicking "connect" on such a "reported" server is only a shortcut for entering yourself the IP and port in a "connect to" - but this client-server connection is independant from the connection with the central server.

IMO, the chat room should be a standard IGame with 10+ "players". This would be a simple yet nice showcase and code example.

miran
Member #2,407
June 2002

Those are some interesting ideas, especially the one with the chatroom being an implementation of IGame. But I think I'll keep it the way it is suggested in v2.08. I want the chatbox to be a reusable kind of widget so that you would still be able to talk with the other players if you wanted to while playing.

As for the server/client architecture of the system, I thought everything would be done through the central server. The server would keep a list of players and active games, the clients would send messages to the server and it would rout them to their destination. This probably wouldn't work for fast action games or situations where there are a lot of active games at the same time, but I think that won't be much of a problem...

--
sig used to be here

Audric
Member #907
January 2001

I discarded the idea of a central server distributing network packets, as :
- it would hog the hosts's bandwidth - and depend on his availability
- Player A in Europe + server in the US + Player B in Europe = trouble

miran said:

I want the chatbox to be a reusable kind of widget so that you would still be able to talk with the other players if you wanted to while playing.

Amgc2 can easily call an IGame function, but IGame functions cannot easily call an amgc2 thing. Especially if it's a MASking widget contained in an Amgc class - this requires linking with amgc and masking, which kind of breaks the concept of plug-in games.
I'll let you think if you can find a pretty workaround, personnally, I see 2 valid ones :
1) Use IRC or an external Instant Messenging program in a second window, duh :) This does the trick for setting up a game ("my server is on IP xxxx" etc) and in-game communication, and 'survives' through game overs and crashes (This is a development workshop, after all).
2) Just let the programmer implement his own say() and say_to(). After all, these are the easiest to implement, they can't break the synchronisation. And it's the game's responsibility to integrate the input and display and make it unique to the game. Ie: like the macros in Diablo2, the num.pad sends audio messages with your character's voice ( follow me / take this / thank you / help me / DIE! )

edit Now I think I see a possible plugin-safe implementation: a key bringing down the full amgc2 box with history as a pop-up over the game (like in pause mode), and a virtual
IGame::MessageNotify(int playernum, char *message_string)
available for custom 'alert' implementation (ring a bell, show the string somewhere, etc.)



Go to: