Code Monkey home page Code Monkey logo

creer's Introduction

Creer

The automatic code generating script for the Cadre framework, intending to create base code for a simple game structure for the rest of the framework.

{Cadre}

All inspiration taken from MST's SIG-GAME framework, and most of the terminology is assuming some familiarity with it as this is a spiritual successor to it.

Requirements

Python 3.4.3+ is required, as are the python packages Mako, binaryornot, and PyYAML.

To install all these python packages, using pip is probably your best bet.

pip install -r requirements.txt

How to use

First, pull cadre 'git clone https://github.com/siggame/Cadre.git'

Next, go into the cadre foldier and run this: './init.sh' You should get messages out it successfully downloading the different repositories. If it fails: replace "[email protected]:" in each of the url paths with "https://github.com/" If it still doesn't work, contact fellow siggame members for support. This is then the point where you would run pip install -r requirements.txt

Finally you can type the gen command. use --test to just test if it works without writing anything. 'python main.py [game name] -i ../Cerveau -o .. --test'

you may remove the -o and it will dump it in the default output file, and you may replace .. with whatever destination you wish.

Merging

One of the biggest pains with the old codegen was manually merging code between codegen runs. Creer is smart and can do the merging for you! Just add the --merge tag and target the Cadre repo you want to merge as the input and output, and it will automatically merge your code changes via code introspection.

Templates

Every folder in the -i input folders should have a _templates/ folder present inside it. the folder/file names inside it should be using Mako syntax. if the file contains ${obj_key} then every game class within the game data you are evaluating for will be generated. For examples look at the Cerveau and Joueur clients that are part of the Cadre framework.

The syntax is all Mako, to give you the full power of Python when templating your Cadre projects.

If your file is a binary files (such as an image), it's file path will still be templated, however it's contents will not and it will just be copied to the output directory/directories like any other file.

Game Structure

Games are defined by a data file that describes the Game, GameObjects within it, and the AI competitors code, and the entire structure is incredibly flexible.

Data File

Each main data file should describe your game structure, and can inherit from other data files to keep games DRY.

All of these are kept within the data/ directory. base.yaml is the base game prototype. It will be included in every game, regardless if you explicitly included it or not.

The rest are optional. Though generally for MegaMinerAI type games you will want to include turnBased and twoPlayer as parent datas.

For examples on other data files, see the various already completed Cadre games.

Types

All variables are cross language safe and can be any type of:

  • void: No type (null)
  • int: Integer
  • float: Floating Point Number
  • string: Text
  • boolean: True or False
  • GameObject: An instance of a game object class defined in the data file. Considered "primitive" to clients to support cool things like cycles.
  • list<valueType>: An ordered container of another game object. Can be multi-dimensional (e.g. a list of lists of ints)
  • dictionary<keyType, valueType>: A mapping of keys to values, and just as lists can be multi-dimensional.

Obviously different languages support these "primitives" in different ways, but all Creer compatible projects should use the fastest, most popular and easy to understand implementation (e.g. use standard libraries and practices).

With support for basically all the primitives, and more complex containers and classes any game structure should be possible. Supporting more complex ideas such as cycles (e.g. a GameObject having reference to itself), and multi-dimensional containers prevents "hacks" that other games using older frameworks needs such as "UnitTypes" classes which held static variables on "Unit" classes.

Note: Just because you can make weird data structures, like a dictionary indexed by lists mapping to another dictionary...and so on, does no mean you should. Generally we only recommend lists and dictionaries be valued by non list/dictionary primitives. Multi-dimensional data structures get weird cross language, and you are probably making your game API too complex for competitors at that point.

Functions

All functions, both as part of GameObjects and the AI classes can take any number of arguments of any of the above types (with optional args), and returns any type. AI returns are sent back to the server and GameObject returns are purely server side with the result "returned" over the TCP socket connection to clients.

Documentation

Every class, attribute, function, argument, etc must be documented. If you fail to provide a description in your data somewhere Creer will tell you. This is so heavily enforced because Creer writes code that other developers and competitors need to understand quickly, so proper and robust documentation is key.

Other notes

Try to have git installed via your command line git so the version of this repo can be added to the generated files. This will help in tracking if files were updated when pushed.

creer's People

Contributors

jacobfischer avatar jawbone999 avatar jeffreystrahm avatar mastercash avatar mnuck avatar reginaldjefferywatson avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

creer's Issues

Remove serverPredefined

a few base templates have serverPredefined as a vestigial tag from older versions. The Cerveau template still uses it in 1 place. That needs to be fixed so this old flag can be completely removed

Better error messages for corrupt Creer merge tags

So normally tags look like this:

        // <<-- Creer-Merge: render -->>
        // render where the Port is
        // <<-- /Creer-Merge: render -->>

However, if a character accidentally gets deleted, e.g.:

        // <<-- Creer-Merge: render -->
        // render where the Port is
        // <<-- /Creer-Merge: render -->>

The > character at the end of the first line is missing

Creer blows up trying to merge them, because the tags are malformed. It should tell the user something like an end tag was found without an opening tag.

Option to disable description checking

It's too specific: one such example is that doc strings MUST end in '.' and not any other valid punctuation, such as '!'.
Also there are legitimate uses for wanting to start with a lowercase letter (e.g. true or false)

Duplicate Lines

Creer/creer/default.py

Lines 104 to 108 in c1683ae

if not 'attributes' in obj:
obj['attributes'] = {}
if not 'attributes' in obj:
obj['attributes'] = {}

Unless I am mistaken, this is just a duplicated logic and one of them can be removed.

Template validation allows game objects with same name as game

The attached creer.yaml (which has a .txt suffix so github will let me upload) passes template validation and creates clients. The c++ client fails to build:

In file included from /home/mnuck/rebot/Cadre/Joueur.cpp/games/botnet/ai.hpp:4:0,
                 from /home/mnuck/rebot/Cadre/Joueur.cpp/games/botnet/ai.cpp:4:
/home/mnuck/rebot/Cadre/Joueur.cpp/games/botnet/impl/botnet.hpp:23:7: error: using typedef-name ‘using Botnet = class std::shared_ptr<cpp_client::botnet::Botnet_>’ after ‘class’
 class Botnet : public Game_
       ^
In file included from /home/mnuck/rebot/Cadre/Joueur.cpp/games/botnet/impl/../game.hpp:22:0,
                 from /home/mnuck/rebot/Cadre/Joueur.cpp/games/botnet/impl/botnet.hpp:13,
                 from /home/mnuck/rebot/Cadre/Joueur.cpp/games/botnet/ai.hpp:4,
                 from /home/mnuck/rebot/Cadre/Joueur.cpp/games/botnet/ai.cpp:4:
/home/mnuck/rebot/Cadre/Joueur.cpp/games/botnet/impl/../impl/botnet_fwd.hpp:19:40: note: ‘using Botnet = class std::shared_ptr<cpp_client::botnet::Botnet_>’ has a previous declaration here
 using Botnet = std::shared_ptr<Botnet_>;

I suspect the issue is that the game is named "Botnet" and so is the in-game object.

As a creer.yaml author, I want to be blocked from instantiating clients that will not compile. Suggest an explicit check for same name.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.