资源说明:turn-based 2d engine for bot challenges
This project is a platform for bot challenges. Currently it is under construction, there is only some prototype that shall be improved. How to see it at work: 1. Clone it 2. Install nodejs >= 0.8.9 3. In the local repository run npm install 4. Run server (require NodeJS >= 0.8.9) node ./games/smart-dog/server/smart_dog_server.js & 5. Open site http://localhost:3000 6. Run 2 or more sample bots: ./clients/js-client/player1.bat & ./clients/js-client/player2.bat & or ./clients/js-client/player1.sh & ./clients/js-client/player2.sh & 7. Observe game on site TODO: +0. Guidelines +1. Game logic (see GameFactory, Player, Dog, etc.) + Done (Grishin) + Sheep logic + Dogs fight + Unit tests for it + split turn in 2 phases: player turn (before,after) - move dogs, npc turn (before, after) - move sheeps +2. Persistence (save to DB, see MemoryStorage class) +3. Entry point for bots (command-line client, etc) 4. Development tools (turns replays, etc) 5. Offline replay (ReplayDataStorer shall put html page near json) +6. Rendering ('barking' and other sounds, animated moval, probably sprites) *7. Website * In progress - player page - list of games, winning count, replay/realtime view of latest/current game shall be updated in runtime! + game page - improve design - list of players * list of games - active/finished filter, paging, design - tournament creation/results review (see below) 8. Players balancer - now it just waits for players to join and starts a game with first 2-4 of them. It shall make sure that all players play same amount of games - tournament: user specifies players, maps, and then server schedules games to be played and awaits required players 9. Improve data format to minimize size of turns/replays/data transferred (base64 or something other binary)? 10. Unit tests! 11. Error processing - when player fails - it shall have -10 score, game shall be marked +12. Memory leaks - currently server allocates a lot of memory. Probably listeners, or non-closed connections +13. Game rules page - with inlined behavior demos (replays) + In progress (Grishin) ------------------------------------------------ Code guidelines Common: - indent is 2 spaces - brace on the same line with if, function, while, etc. - start private methods with _ - do NOT access private directly members (i.e. something like { return object.id }) exception: struct-like objects - introduce getters/setters for accessing (__defineGetter__/__defineSetter__) or get/set methods - when to use get/set methods? when they may be overriden (virtual) - when to use getters/setters? when they shall not be overriden (final) ? probably store private members in a separate field? like this: function Object() { this._ = {}; this._.name = ""; this.__defineGetter('name', function() {return this._.name}); } will try for some cases ! so search '._' shall show only 'this._' strings - use .bind instead of 'that' variables - introduce Event sub-object to store event constants, like this: function Object() {} Object.Event = { CHANGED: "object.changed", DELETED: "object.deleted" } GameObject: Some special case. Has "private" object p which is not a field of GameObject, so it shall be transfered to any method if it requires some private fields. Override 'extends' method in subclasses to add new properties/methods. Game: All events between players or game objects are go through the Game object. Player: No specific comments Game,GameObject,Player: Have method 'toState' which returns the object's snapshot. This snapshot is generated once after each turn (still not true for GameObject) and it is what is returned to clients classes (like SocketController and SocketView). Client classes may reduce state or somehow reformat it before passing further, but they shall not call to the real object methods because they may have inconsistent state. Summary: toState shall return latest stable state which corresponds to the beginning of current Turn, and shall do it as quick as possible GameObjectsFactory: A heart of the specific game. Contains references to all game-specific objects and logic. Any game-specific logic shall be implemented here or in the corresopnding game objects SocketController: Has single entry-point for client (#receive), parses the command and calls its own method with command name. Shall use plain sockets for simplification SocketView: Has single entry-point for client (#receive), parses the command and calls its own method with command name. Shall use socket.io sockets for HTML client which uses websockets. Shall use ReplayFormat helper to prepare view, so the same renderer may be used for online and replay
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。