Commits

Mark Johnson committed 430e550

Coded some bits and pieces around the main functional elements of the script.
Then tried to do the maths for the transactions and failed. To be continued.

Comments (0)

Files changed (3)

.hgignore

Empty file removed.

MahjonggScorer.psproj

 [PyScripter]
-Version=2.4.1.0
+Version=2.4.3.0
 
 [Project]
 ClassName=TProjectRootNode
 [Project\ChildNodes\Node0]
 ClassName=TProjectFilesNode
 
+[Project\ChildNodes\Node0\ChildNodes\Node0]
+ClassName=TProjectFileNode
+FileName=C:\Users\mark\Documents\My Projects\Python Projects\Mahjongg Scorer\MahjonggScorer.py
+
+[Project\ChildNodes\Node0\ChildNodes\Node1]
+ClassName=TProjectFileNode
+FileName=C:\Users\mark\Documents\My Projects\Python Projects\Mahjongg Scorer\README.txt
+
+[Project\ChildNodes\Node0\ChildNodes]
+Count=2
+
 [Project\ChildNodes\Node1]
 ClassName=TProjectRunConfiguationsNode
 

MahjonggScorer.py

 #-------------------------------------------------------------------------------
 #!/usr/bin/env python
 
-def main():
-    print("Hello, World!")
+# Define Player Class
+class Player():
+    def __init__(self, name):
+        self.name = name
+        self.total_score = 0
+        self.hand_score = 0
+        self.is_hand_winner = False
 
-if __name__ == '__main__':
-    main()
+# Instantiate the four players
+# player1 = Player(input("Player 1 Name:"))
+# player2 = Player(input("Player 2 Name:"))
+# player3 = Player(input("Player 3 Name:"))
+# player4 = Player(input("Player 4 Name:"))
+
+# Lazytown version while testing
+player1 = Player("Arthur")
+player2 = Player("Belinda")
+player3 = Player("Charlie")
+player4 = Player("Dill")
+
+playerlist = [player1, player2, player3, player4]
+
+winner = input("Who won this hand {} {} {} or {}?".format(player1.name,
+                                                          player2.name,
+                                                          player3.name,
+                                                          player4.name,))
+
+print("Please enter the scores:")
+for player in playerlist:
+    player.hand_score = int(input(player.name))
+    if player.name == winner:
+        player.is_hand_winner = True
+        winning_score = player.hand_score
+    else:
+        pass
+
+print("{} won this hand with a winning score of {}".format(winner,
+                                                           winning_score,))
+
+# The addition and subtraction calculations
+# This is not working. It adds and subtracts too many times. What needs
+# happen is for the player list to get sorted in to Winner, Highest Loser,
+# Next Highest, Lowest and then for the following transactions to take place
+# 4 pays 1 double
+# 4 pays 3 
+# 4 pays 2
+# 3 pays 1 double
+# 3 pays 2
+# 4 pays 1 double
+# But I am not sure if there is some kind of smart maths sequience to run
+# My next step will be to write the transaction function and process that
+#sequence
+
+for give_player in playerlist:
+    if give_player.is_hand_winner == True:
+        pass
+    else:
+        for get_player in playerlist:
+            if get_player.name == give_player.name:
+                pass
+            else:
+                diff = get_player.hand_score - give_player.hand_score
+                if get_player.is_hand_winner == True:
+                    diff = diff *2
+                    if diff > 0:
+#                       give_player.total_score -= diff
+                        get_player.total_score += diff
+                    else:
+                        pass
+                else:
+#                   give_player.total_score -= diff
+                    get_player.total_score += diff
+
+#Display the end results
+print("The scores are:")
+for player in playerlist:
+    print(player.name+" : "+str(player.total_score))