Skip to content

Commit 6c36b21

Browse files
committed
Initial commit
- Add scrabble.py - Add requirements.txt to include packages required - Add a README file to describe how to run the game
1 parent 53773bd commit 6c36b21

File tree

7 files changed

+145
-0
lines changed

7 files changed

+145
-0
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "Scrabble/Scrabble/src/goslate"]
2+
path = Scrabble/Scrabble/src/goslate
3+
url = https://github.com/yeahwhat-mc/goslate

Scrabble/README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# SCRABBLE
2+
3+
## Definition
4+
This project is the Scrabble game which can be played between many players.
5+
6+
### Project structure :
7+
8+
- scrabble.py
9+
- requirements.txt
10+
- README.md
11+
12+
## Libraries
13+
### PyDictionary:
14+
Returns meaning, synonyms, antonyms for a word (scraping dictionary.com) limit the no of results also get meaning, synonyms and antonyms in different color..[seemore](https://pypi.org/project/Py-Dictionary/)
15+
16+
## Installing Libraries
17+
The requirements.txt file that has the library used which simply can be used to install the libraries through the package manager [pip](https://pip.pypa.io/en/stable/).
18+
19+
```bash
20+
pip install -r requirements.txt
21+
```
22+
## Usage
23+
```bash
24+
python scrabble.py
25+
```
26+
The players can exit the game by typing Y or else continue the game by Enter.
27+
```python
28+
**********Welcome to the Scrabble game**********
29+
Let's start playing!!
30+
31+
How many players? 2
32+
Player 1: A
33+
Player 2: B
34+
****************************************
35+
36+
A | Type a word: hat
37+
B | Type a word: pot
38+
If exit, type Y:
39+
```
40+
41+
## Functioning
42+
The project.py contains 6 functions including the main function.
43+
Main function prints out the user interface of the game.
44+
45+
### valid(word) function :
46+
This function takes a word and check its validity by looking for its availability in the PyDictionary. If it is available, returns True else it returns False
47+
48+
### compute_score(word) function :
49+
This function computes and outputs the score of a word. If the word is not alphabetic or if the word is not valid, exceptions are arisen.
50+
51+
### player_count() function :
52+
This function prompt the user for an input of number of players. Until a valid integer is typed, the function is called. Finally the count is returned.
53+
54+
### get_input(score_board) function :
55+
This function takes an empty scoreboard dictionary, prompts the players to type their words in number of rounds until the exit term Y is typed and the scores are added simultaneously. Whenever a player types an invalid format of word, the player will be requested again. The function returns a dictionary scoreboard of the players with their score
56+
57+
### winner(score_board) function :
58+
This function takes the scoreboard and finds the winner or winners, then output the result announcement accordingly.
59+
60+
## Author: Nashira

Scrabble/Scrabble/src/goslate

Submodule goslate added at d6d511a

Scrabble/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
git+https://github.com/yeahwhat-mc/goslate#egg=goslate
2+
Py-Dictionary

Scrabble/scrabble.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
from PyDictionary import PyDictionary
2+
3+
def main():
4+
print("\n" + '*'*10 + "Welcome to the Scrabble game" + '*'*10 + "\n" + "Let's start playing!!\n")
5+
score_board = {}
6+
for i in range(player_count()):
7+
player = input(f"Player {i+1}: ")
8+
score_board[player] = 0
9+
print('*'*40 + "\n")
10+
print(winner(get_input(score_board)).center(40, " ") +"\n")
11+
print('*'*40 + "\n"+"Thank you for your time. Have a Nice day!")
12+
13+
def valid(word):
14+
if PyDictionary().meaning(word, True) == None :
15+
return False
16+
else:
17+
return True
18+
19+
def compute_score(word):
20+
score_list = {'a':1, 'b':3, 'c':3, 'd':2, 'e':1, 'f':4, 'g':2, 'h':4, 'i':1, 'j':8, 'k':5, 'l':1, 'm':3,
21+
'n':1, 'o':1, 'p':3, 'q':10, 'r':1, 's':1, 't':1, 'u':1, 'v':4, 'w':4, 'x':8, 'y':4, 'z':10}
22+
score = 0
23+
if word.isalpha():
24+
if valid(word):
25+
for i in word:
26+
score += score_list[i.lower()]
27+
return score
28+
else:
29+
raise NameError
30+
else:
31+
raise ValueError
32+
33+
def player_count():
34+
while True:
35+
try:
36+
count = int(input("How many players? "))
37+
except ValueError:
38+
print("Please type a number in integer format.")
39+
continue
40+
else:
41+
return count
42+
break
43+
44+
def get_input(score_board):
45+
while True:
46+
for player in score_board:
47+
while True:
48+
try:
49+
word = input(f"{player} | Type a word: ")
50+
score_board[player] += compute_score(word)
51+
except BaseException:
52+
print("Please type a valid word.")
53+
continue
54+
else:
55+
break
56+
57+
if input("If exit, type Y: ") == "Y":
58+
print('*'*40 + "\n")
59+
break
60+
else:
61+
continue
62+
return score_board
63+
64+
def winner(score_board):
65+
sorted_scores = sorted(score_board.items(), key=lambda x: x[1], reverse= True)
66+
max = sorted_scores[0][1]
67+
winners = [sorted_scores[0][0]]
68+
for i in sorted_scores[1:]:
69+
if i[1] == max:
70+
winners.append(i[0])
71+
if len(winners) > 1:
72+
return f"It's a tie. The winners are {', '.join(winners)}!!"
73+
else:
74+
return f"The winner is {winners[0]}!"
75+
76+
if __name__ == "__main__":
77+
main()

Scrabble/src/goslate

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit d6d511a9c001fe0b5c1cf947fd650770e9794f1d

src/goslate

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit d6d511a9c001fe0b5c1cf947fd650770e9794f1d

0 commit comments

Comments
 (0)