Giter Club home page Giter Club logo

janggi's Introduction

portfolio-project

Write a class named JanggiGame for playing an abstract board game called Janggi. Please read the "Board", "Pieces" and the overall "Rules" section on the Wikipedia page. You do not have to implement the rules regarding perpetual check, position repetition, any kind of draw or the miscellaneous rules. You do need to correctly handle checkmate. You also need to correctly handle all piece-specific rules, e.g. generals aren't allowed to leave the palace, horses and elephants can be blocked, cannons cannot capture other cannons, etc. A good video describing the rules is here.

A general is in check if it could be captured on the opposing player's next move. A player cannot make a move that puts or leaves their general in check. The game ends when one player checkmates the other's general. You don't actually capture a general, instead you have to put it in such a position that it cannot escape being in check, meaning that no matter what, it could be captured on the next move. This works the same as in chess, if you're familiar with that game.

Unlike chess, Janggi allows you to pass a turn and thus there is no stalemate (a scenario when no legal moves can be made).

Your program should have Blue and Red as the competing players and Blue as the starting player. You do not need to implement any special mechanism for figuring out who can start the game.

Locations on the board will be specified using "algebraic notation", with columns labeled a-i and rows labeled 1-10, with row 1 being the Red side and row 10 the Blue side. Your initial board setup should have the Elephant transposed with the Horse, on the right side, as seen on the image from Wikipedia. You can use this spreadsheet as a reference to understand the initial board layout as well as to simulate your moves.

You're not required to print the board, but you will probably find it very useful for testing purposes.

Your JanggiGame class must include the following:

  • An init method that initializes any data members.
  • A method called get_game_state that just returns one of these values, depending on the game state: 'UNFINISHED' or 'RED_WON' or 'BLUE_WON'.
  • A method called is_in_check that takes as a parameter either 'red' or 'blue' and returns True if that player is in check, but returns False otherwise.
  • A method called make_move that takes two parameters - strings that represent the square to move from and the square to move to. For example, make_move('b3', 'b10'). If the square being moved from does not contain a piece belonging to the player whose turn it is, or if the indicated move is not legal, or if the game has already been won, then it should just return False. Otherwise it should make the indicated move, remove any captured piece, update the game state if necessary, update whose turn it is, and return True.

If the make_move method is passed the same string for the square moved from and to, it should be processed as the player passing their turn, and return True.

Feel free to add whatever other classes, methods, or data members you want. All data members must be private. Every class should have an init method that initializes all of the data members for that class.

Here's a very simple example of how the class could be used:

game = JanggiGame()
move_result = game.make_move('c1', 'e3') #should be False because it's not Red's turn
move_result = game.make_move('a7,'b7') #should return True
blue_in_check = game.is_in_check('blue') #should return False
game.make_move('a4', 'a5') #should return True
state = game.get_game_state() #should return UNFINISHED
game.make_move('b7','b6') #should return True
game.make_move('b3','b6') #should return False because it's an invalid move
game.make_move('a1','a4') #should return True
game.make_move('c7','d7') #should return True
game.make_move('a4','a4') #this will pass the Red's turn and return True

The file must be named: JanggiGame.py and it should not contain any test code outside the main() function. Your code for this project should not be made public, in any manner, until after the term has ended.

janggi's People

Contributors

nilloc95 avatar

Watchers

 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.