Giter Site home page Giter Site logo

kaevupoiss / backgammon Goto Github PK

View Code? Open in Web Editor NEW

This project forked from weekend37/backgammon

0.0 0.0 0.0 51 KB

Backgammon interface in python for the 2nd and 3rd computational assignments in Computational Intelligence.

Python 83.59% C 16.41%

backgammon's Introduction

Backgammon

Backgammon interface for the 2nd and 3rd computational assignments in Computational Intelligence.

The board interpretation

The game is set up in the Backgammon.py file. To play a game, simply run the program. The two players are defined as player 1 and player -1. The board has 29 positions:

  • positions 1-24 are the labeled on-board positions
  • positions 25 and 26 are the jails for when a piece is "killed" (25 is the jail for player 1 and 26 for player -1)
  • positions 27 and 28 represent the position of the pieces who have been beard off (27 for player 1 and 28 for player -1)
  • position 0 is pointless and is not being used...

The number of pieces in a certain possition of the board is represented by n where |n| is the number of pieces in the position and sign(n) indicates which player owns the pieces in the position.

few examples:

  • board[23] = 3 means that player 1 has 3 player on the 23rd position of the board.
  • board[21] = -10 means that player -1 has 10 pieces on the 21st position of the board.
  • board[28] = -2 would mean that player -1 has beared off two pieces.

Moving the pieces

The game is played between agents. Your main agent should be coded and trained in the agent.py file. When the Backgammon.py program is executed, it imports your agent and uses his decisions to make moves. The moves are simple. They are written as lists of two numbers where the

  • first number represents the position from where you wish to move your piece from
  • and the second number represents the position to where you wish to move your piece

When an agents is to move, it returns a couple of moves since he rolls two dices and therefore has to make two moves. If there are less then 2 moves available (1 or 0) it can return fewer moves.

When a player rolls the same number on the dice in Backgammon, he is allowed to play 2 times. That is 2 moves 2 times. When that happens, the agent should not return 4 moves in one. Instead, the Backgammon.py file asks the agent two times to make his move.

To decide on which move to make feel free to use the functions legal_moves, legal_move and update_board as you wish as well as making your own versions of them.

example: to make the following move: http://www.bkgm.com/faq/gif/pickandpass.gif the agent of player 1 has to return the list [(10,5),(5,3)]

Thoughts and advices

Running time

running time for one game is ~55ms per game or just under a minute per 1000 games when the players are only random agents that are not training. When training your agents, you might want to think cautiously about the time complexity of your code. Feel free to make your own faster code of Backgammon (and then share it!) but make sure your agents will be integrable for this version.

Different perspectives

Your players have to be able to both play as player 1 and player -1. For this to be possible you can either

  • flip the board and always make your player feel like player one. The code has already been made in the file flipped_agent.py. There you can find the functions flip_board and flip_move as well as an example of an agent that uses them correctly.
  • account for both cases (as the moves will be different for the different players). Note that the training time will be twice as much as for the other option.

Cheating

To save running time, the coded game doesn't check if your player is cheating. Because of that, you have to be careful that your player isn't doing so (e.g. accidentally making 7 moves instead of 2 or maybe moving his piece from the starting position to the end position and therefore always beating his opponents). The moves from the agents will be checked before they are submitted in the final tournament.

backgammon's People

Contributors

weekend37 avatar

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.