All Projects → benjamincrom → scrabble

benjamincrom / scrabble

Licence: MIT license
Implements Scrabble. Also allows user to recover all game moves from given board and score list as well as brute-force find best move.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to scrabble

deck.zone
A board game creation tool.
Stars: ✭ 19 (-50%)
Mutual labels:  board-game
deerportal
Full of the diamonds 💎 board game driven by a 🦌 Deer 🦌 god and classical elements 🔥 💦 💨 🌍
Stars: ✭ 31 (-18.42%)
Mutual labels:  board-game
Imperial-Assault-Skirmish-Map-Project
Maps for Imperial Assault skirmish scenarios: check missions or print for playmats
Stars: ✭ 69 (+81.58%)
Mutual labels:  board-game
shogi-pieces
Shogi (Japanese Chess) pieces and boards
Stars: ✭ 25 (-34.21%)
Mutual labels:  board-game
SpaceAlertMissionGenerator
Mission Generator For Space Alert Board Game On Android
Stars: ✭ 15 (-60.53%)
Mutual labels:  board-game
quinto
a board game lost to the sands of time
Stars: ✭ 27 (-28.95%)
Mutual labels:  board-game
Alphazero gomoku
An implementation of the AlphaZero algorithm for Gomoku (also called Gobang or Five in a Row)
Stars: ✭ 2,570 (+6663.16%)
Mutual labels:  board-game
connect4
🎮 It is a two-player connection game in which the players first choose a color and then take turns dropping one colored disc from the top into a seven-column, six-row vertically suspended grid. The pieces fall straight down, occupying the lowest available space within the column, user wins by forming row of four of same color
Stars: ✭ 18 (-52.63%)
Mutual labels:  board-game
boardgame-socketplayer
A generic board game socket client
Stars: ✭ 21 (-44.74%)
Mutual labels:  board-game
Mzinga
Open-source software to play the board game Hive.
Stars: ✭ 57 (+50%)
Mutual labels:  board-game
piecepackr
Board Game Graphics in R
Stars: ✭ 44 (+15.79%)
Mutual labels:  board-game
immutable-gametree
An immutable game tree data type.
Stars: ✭ 18 (-52.63%)
Mutual labels:  board-game
NemeStats
NemeStats is a completely free website for tracking board games played among a relatively stable group of players.
Stars: ✭ 43 (+13.16%)
Mutual labels:  board-game
AccessBattle
Free non-commercial implementation of the game "Rai-Net Access Battlers"
Stars: ✭ 15 (-60.53%)
Mutual labels:  board-game
Carcassonne
A digital version of the board game Carcassonne, implemented in Java. This desktop computer game supports up to five players at the same time (shared-screen multiplayer mode).
Stars: ✭ 70 (+84.21%)
Mutual labels:  board-game
besogo
Embeddable SGF editor/viewer for the game of Go (aka Weiqi, Baduk)
Stars: ✭ 82 (+115.79%)
Mutual labels:  board-game
shogi-rs
A Bitboard-based shogi library in Rust. Board representation, move generation/validation and time control utilities.
Stars: ✭ 39 (+2.63%)
Mutual labels:  board-game
tictacNET
Solving Tic-Tac-Toe with Neural Networks.
Stars: ✭ 17 (-55.26%)
Mutual labels:  board-game
chess
The game of Chess
Stars: ✭ 25 (-34.21%)
Mutual labels:  board-game
ColorByNumber-iOS
Color by Number: a pixel coloring game on iOS.
Stars: ✭ 50 (+31.58%)
Mutual labels:  board-game

Table of Contents

Scrabble

This package implements the game of Scrabble and also adds features that recover previous moves as well as determine the best next move for a given Scrabble game.

Installing from pypi

pip3 install scrabble

Installing from source

git clone [email protected]:benjamincrom/scrabble.git
cd scrabble/
python3 setup.py install

Testing

Tests take about two hours to run on an average machine.

python3 setup.py test

Recover Scrabble Game

Recover the moves of a Scrabble game given only the final board and the list of player scores for each move.

Usage:

$ recover_scrabble_game [INPUT_FILENAME]

See scrabble/tests/sample_input_files for examples of correctly formatted input files

Example:

$ recover_scrabble_game ./tests/sample_input_files/sample_input30.json

[
    [
        [(('h', 8), '*OWDY')],
        [(('e', 10), 'R(A)ZE')],
        [(('h', 12), '(Y)IP')],
        [(('b', 13), 'MOV(E)')],
        [(('c', 6), 'GU(Y)')],
        [(('l', 10), '(D)OTE')],
        [(('e', 3), '(G)UILE')],
        [(('i', 2), 'B(E)ER')],
        [(('i', 5), '(R)IP')],
        [(('g', 2), 'H(I)NT')],
        [(('l', 2), '(D)UNE')],
        [(('j', 12), '(PI)TA')],
        [(('h', 9), '(O)R*')],
        [(('o', 13), 'LI(T)')],
        [(('e', 15), 'BANAN(A)')]
    ], [
        [(('d', 11), 'FAME(D)')],
        [(('d', 8), 'CRIE(*)')],
        [
            (('i', 12), '(I)T'),
            (('j', 12), '(P)I'),
            (('i', 13), 'TIGHT')
        ],
        [(('e', 3), 'GRAYE(R)')],
        [(('l', 10), 'DAS(H)')],
        [(('o', 8), 'OV(E)N')],
        [(('c', 4), 'JA(R)')],
        [(('c', 4), '(J)I(G)')],
        [(('b', 10), 'LOO(M)S')],
        [
            (('l', 2), 'DOWEL'),
            (('i', 5), '(RIP)E')
        ],
        [(('o', 1), 'R(E)ASON')],
        [(('m', 13), '(T)AX')],
        [(('l', 15), 'E(X)IT')],
        [
            (('a', 14), 'I(S)'),
            (('a', 14), 'ID')
        ],
        [(('j', 7), 'SE(*)K')]
    ]
]

Play Scrabble Game

Create a new Scrabble game object

  • scrabble.main.ScrabbleGame(num_players)
>>> from scrabble.main import ScrabbleGame
>>> game = ScrabbleGame(num_players=4)
>>> game
  abcdefghijklmno
1 _______________
2 _______________
3 _______________
4 _______________
5 _______________
6 _______________
7 _______________
8 _______★_______
9 _______________
10_______________
11_______________
12_______________
13_______________
14_______________
15_______________
[[G, T, E, A, D, P, C], [E, I, S, O, N, G, M], [M, S, T, U, R, O, J], [E, *, L, A, R, I, A]]
Moves played: 0
Player 1's move
72 tiles remain in bag
Player 1: 0
Player 2: 0
Player 3: 0
Player 4: 0

Make Move

  • scrabble.main.ScrabbleGame.place_word(word, start_location, is_vertical_move)

Place a word from the rack of the next player onto the board. If the move is legal you will be prompted as to whether or not the move was successfully challenged. If the move goes through through then the method will return True. If the move is illegal you will not receive a challenge prompt and the method will return False.

>>> game.place_word(word='GATE', start_location=('h', 8), is_vertical_move=False)
Challenge successful (Y/N)N
True

>>> game
  abcdefghijklmno
1 _______________
2 _______________
3 _______________
4 _______________
5 _______________
6 _______________
7 _______________
8 _______GATE____
9 _______________
10_______________
11_______________
12_______________
13_______________
14_______________
15_______________
[[D, P, C, O, E, F, N], [E, I, S, O, N, G, M], [M, S, T, U, R, O, J], [E, *, L, A, R, I, A]]
Moves played: 1
Player 2's move
68 tiles remain in bag
Player 1: 10
Player 2: 0
Player 3: 0
Player 4: 0

Find Best Move (Brute Force)

  • scrabble.main.ScrabbleGame.get_best_move()

Find the best move via brute-force search. Returns the move score and move tuple of the form (location, word, is_vertical_move).

>>> game.get_best_move()

(27, (('l', 4), 'EGOISM', True))

Exchange Tiles

  • scrabble.main.ScrabbleGame.exchange(letter_list)

Exchange up to all a player's rack tiles as long as the bag has at least one entire rack of tiles remaining.

>>> game.exchange(letter_list=['E', 'I', 'S', 'O'])
True

>>> game
  abcdefghijklmno
1 _______________
2 _______________
3 _______________
4 _______________
5 _______________
6 _______________
7 _______________
8 _______GATE____
9 _______________
10_______________
11_______________
12_______________
13_______________
14_______________
15_______________
[[D, P, C, O, E, F, N], [A, P, R, M, N, G, M], [M, S, T, U, R, O, J], [E, *, L, A, R, I, A]]
Moves played: 1
Player 3's move
68 tiles remain in bag
Player 1: 10
Player 2: 0
Player 3: 0
Player 4: 0

Conclude Game

  • scrabble.main.ScrabbleGame.conclude_game(empty_rack_id=None)

Calculates final scores and declares a winner. This method will automatically be called and bonuses automatically awarded if one player has an empty rack (plays out) when the tile bag is empty.

>>> game.conclude_game()
Game Over! Player 1 wins with a score of 10
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].