Code Monkey home page Code Monkey logo

challengebot's Introduction

ChallengeBot

Getting Started

These instructions will get you a copy of the project up and running on your local machine.

Prerequisites

Main

Minor but not insignificant

How to run

Front-end

The website can run independently, without any dispatcher supporting it. The dispatcher is there to evaluate sources. In order to start the webserver.

python manage.py runserver

Ocasionally, models in the front-end may change, and the database needs to reflect those changes, or sql errors in django may occur. To fix that:

python manage.py makemigrations

This will create a migration. If a change was detected, a python source will be save and a migration_name will be given (xyzt) where x, y, z, t are digits. For now, let's assume a new change has the migration_name 0017. You need to take into account which version of the database you are on. Say, if the migration has been done for 0017, you need to apply all versions up until it. If you made just one change, then you only have sqlmigrate that one.

python manage.py sqlmigrate web 0016
python manage.py sqlmigrate web 0017

To create sql queries pending on the database. But in order to apply the changes, type

python manage.py migrate web

Back-end

During testing, the dispatcher will set all jobs from the database to Registered and it will start to evaluate all of them in order. (In its current form)

python run.py

The dispatcher?

Yes. It looks in the database for registered, un-evaluated jobs and completes them. It has a registry of known games which it can execute.

How to debug?

If working with the interface, the chrome console and manage.py terminal might be the only things you need. However, working with the backend can be quite troubling some times. Since games are using sockets to communicate with the clients, i suggest downloading Wireshark, and capturing network packets by applying the following filter:

ip.src == ip.dst

In order to determine to communication, follow the packages. Port 1200 will always be the server, the other ports are the clients. In order to determine which is which, look at the first packets, they will send the server the username of the player.

Writing your game in the back-end

Most of the complicated stuff for basic games are already implemented (how a turn works, adding players, communicating with them etc.) Depeding on which type of game you need to implement, you will use either AbstractGame or PhasingGame as super class. If using a PhasingGame, each phase of the game must be specified and associated with an integer starting from one, self.phase should be changed when necessary to switch to a different phase.

When to use PhasingGame?

When a game has different phases which require player interaction and have different behaviour. Example: Battleships has two game phases. In one, the player puts the ships, in the other, they to shoot the enemy ship.

Logging

Log relevant data which can be used later by a the front-end to show all the data in a pretty way. Do not show the commands sent by user, filter them and show only what they did.

Declaring winners or losers

Each AbstractPlayer comes with its status. If the status of the player is changed anytime during the game from Status.PLAYING to anything else, the player will leave the game and that will be logged. Status.WINNER, Status.LOSER will ask the player to leave nicely, while all other will result in a kick. It is recommended you only change the status of a player in the check function (see implementation for super class used to see what already exists, usually only turns, phases, checks, starts and finished should be implemented). As of new updates, changing the status should occur only through special functions in the AbstractGame class When receiving None as a command, the player must be kicked with Status.TIMEOUT_EXCEEDED.

How to test a game?

Do not use the dispatcher. Create an executable, conveniently placed .py file which loads the game with a port and test list of players. Create a separate client which directly connects to the server using sockets. See (sources-test folder as a reference)

The ranking system

Everytime you set a status of a player to WINNER, they will automatically get the best position possible in the ranking. Everytime you set a status of a player to LOSER, they will automatically get the worst position possible in the ranking. There is another tier of worseness: disqualification. A player's source can be disqualified, which means it will get the disqualified status and cannot be used again. In this case, all players with loser status will be above the players with disqualified.

Experience

After the ranking has been determined, each player will be awarded accordingly to their rank in the ranking. If a player is disqualified, they will not enter the ranking, but others will benefit from their loss. The formula for computing xp gain is

xp_gain = (xp_win * no_players_below + xp_lost * no_players_above) / (no_players - 1) * (author ? 1.5 : 1.0)

Which means the player gets the average of how many players they beat minus how many players beat them. If a player initiates the challenge, they get 150% bonus xp. Be aware as all xp lost will also be multiplied.

There is also a bonus for players which manage to get a source accepted from the first submission: They will automatically start at level 2

How to set experience for a level?

  1. Figure out possible win-rates for different sources and try to predict the meta of the game.
  2. Set win-rates for each level. Try to set as many levels as possible (Recommended for now: 10) (Ex. 1: 33% 2: 50% 3: 66% for a 3-level game)
  3. Set the following values:
xp_win = xp_reach / wins
xp_lost = - level_win_rate * xp_win

Preferabily keep the difference between xp_win and xp_lost Also, if your game accepts draws (such as X and O) figure out a value which is convenient between xp_lost and xp_win. Increase xp_dsq exponentially after each level. Heavily penalize a disqualification in high level, even with 100% in the last level

Example: Level 1 (Win-rate 0%):

xp_reach = 60xp

xp_gain = 20xp

xp_lost = 0xp

xp_draw = 10xp

xp_dsq = -10xp

Level 2(Win-rate 25%):

xp_reach = 100xp

xp_gain = 25xp

xp_lost = -7xp

xp_draw = 8xp

xp_dsq = -20xp

...

Level X(Win-rate: 66%):

xp_reach = 1000xp

xp_gain = 40xp

xp_lost = -27xp

xp_draw = 0xp

xp_dsq = -1000xp

This way, for a player to advance a level, they will either have to:

  • have a good enough win-rate the whole level to beat the established one
  • know the field and challenge players in order to win (because of the 50% xp bonus)

Issues with current system

  1. Farming low-level players (will be solved by increasing xp gain of low level win and decreasing xp lost of low level and decreasing xp gain of win high level and increasing xp lost of win high level).
  2. Continuosly farming same player (a cap on challenging same player will be added soon)
  3. The submission bonus is lost if submissions are reeavaluated

Coding style and coding-related

  • Use as much jquery as you can, avoid javascript
  • OOP and inheritance of already implemented generic stuff is mandatory in back-end. If something needs to be implemented, it must added in such a matter that it is similar to real life situations (even a dice has a class)
  • on front-end there should be just function calls with a few exceptions
  • all forms should be sent through ajax and be validated only on server-side
  • write code as generic as possible, high re-usage is required
  • parts of a function which are related can be spaced out from others (using an empty line)
  • if something that already exists can be written more genericaly, create issues to discuss
  • releases can be made only from the master branch

Mentions

  • Any change to front-end code will result in an immediate change on the server if it is open (except for models and form classes)

Q & A

Q: I changed a coding resource (.js, .css etc.) but the page is still showing the old one. What happened? A: It is cached, CTRL+SHIFT+R should fix it

Q: I changed a png or other image file, why does not it show up? A: Also cached, but you need to clear browser cache this time

Q What are migrations? A: Whenever you change the models, the corresponding database file needs to be updated. A migration means moving data from a database version to another.

Q My code worked before. Now that i merged with master branch it does not. What's the problem? A: Chances are: your database is out of date with the new models. Django tries to find objects according to models.py, not how the database looks. If someone merged to master a change on the models and changed the code which used them, you need to migrate your data to the newest database version (see migrations above)

Restrictions

  • Do not code on master branch unless it is crucial and have approval
  • Do not change models or forms classes unless discussed and approved with @Cronologium. This is a main problem for git pulling (because of migrations) and it should be avoided at all costs or worked with very rarely and at a time.
  • Do not change urls in the urls.py file unless discussed and approved with @Cronologium. For security reasons and not messing up the work of others, you should avoid changing this kind of basic stuff.

Such undiscussed/unapproved changes will not be taken into consideration.

Warnings

  • Adding perma-redirects (302) to links will most likely result in losing rights to access the repo.
  • Any intentional security back-door introduces in the website will result in automatically losing rights
  • Lack of contribution or communication with others results in exclusion without notice

challengebot's People

Contributors

buclucashu avatar tudorvaran avatar

Watchers

 avatar

challengebot's Issues

Display new ranking feature and levels

Now that players can gain experience after winning games, there should be a way to show each level they are on each game and to show the experience gained after each game.

Profile page

What should it include for a player? What could the player customize their profile in such a way to be fun and interactive?

Generic challenge web interface

The display interface for challenges should be less specific for each game and more generic in order to produce faster games.

Test poker

Testing on the back end implemented game poker should be done before adding it to the pool of available games.

Generic Python environment

The python environment should be more generic in order to cover many types of games, not just battleships like it does in this moment

Change text for battleships page

Have a look at the battleships description page(just the description) and change text to be more user friendly (for any user, not just experimented ones)

Dispatch v2

The new dispatcher will communicate with clients using only pipes between processes, no sockets. Client side flushes are required.

Dispatcher v2 with clients using netcat

Experimentation with sources as netcat servers. Possible trade-offs:
easier implementation of games
easier integration of other languages
code easier to understand for the user
Will experiment in the weekend.

Bootstrap fix

The bootstrap link in template gives some performance issues. Sometimes, the url is not very responsive and the user has to wait a long time for it to happen.

Remove bootstrap entirely and solve all css issues which occur. This will lead to a 100KB reduction of page loading

Source selecting management

When a player gets a disqualified status, their source must be disqualified, and the last submitted source should be auto selected.
There should also be a way for the player to select which source they want to be selected.

Source load/"edit"

Give the users the possibility to load their own sources. To edit them, load the source in the game page.

[Blocking]Reanalyze models and restructure them

There are many fields which are not used in the databse and some which are irelevant. A discussion for this has to be made first to restructure this issue.
Once re-modelling begins, a big part of the web interface will be changed, so will the database. This might become an issue while it is done, so it must be done right from the begining.

write readme

In order to have some kind of documentation of the project

Change home page

A design overhaul needs to be done for the home page as it currently does not look good (especially the screenshots)

Fix design

Main design for the webpage is not finished. We need to decide on the color palette and other aspects

Ranking

We need a rank experience for user in order to stimulate them to send submissions and challenge others.
I'm suggesting level-based ranking.
For each level the player need xp, which he gains by:
Submitting a source successfully, after each submission the number of xp drops. Not awarding two submissions in a row.
Winning a game grants xp
Losing makes you lose xp
Tie makes you gain xp equal to a win and a loss
After leveling up a user cannot lose levels.
Bonuses:
150%-200% xp if the user started the challenge. (also loses more if loses the game)
more xp for opponents - players of higher levels than user
less xp for opponents - players of lower levels than user
This requirement only refers to the backend part.

Switch to HTTPS protocol

HTTP is unsafe and even Google intends to drop all websites using this protocol. A switch to HTTPS is MANDATORY.

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.