Merge branch 'master' of https://github.com/NikolajDanger/Gwendolyn
This commit is contained in:
@ -10,7 +10,7 @@ import random
|
||||
#import math
|
||||
import os
|
||||
|
||||
from funcs import helloFunc, cap, imageFunc, logThis, findWikiPage, makeFiles, emojiToNumber, fiarReactionTest, deleteGame, stopServer, checkBalance, giveMoney, triviaCountPoints, triviaStart, triviaAnswer, blackjackShuffle, blackjackStart, blackjackPlayerDrawHand, blackjackContinue, blackjackFinish, blackjackHit, blackjackStand, blackjackDouble, blackjackSplit, parseFourInARow, fourInARowAI, spellFunc, monsterFunc, nameGen, tavernGen, movieFunc, roll_dice, parseChar, parseRoll, critRoll, parseDestiny
|
||||
from funcs import helloFunc, cap, imageFunc, logThis, findWikiPage, makeFiles, emojiToNumber, fiarReactionTest, deleteGame, stopServer, checkBalance, giveMoney, triviaCountPoints, triviaStart, triviaAnswer, blackjackShuffle, blackjackStart, blackjackPlayerDrawHand, blackjackContinue, blackjackFinish, blackjackHit, blackjackStand, blackjackDouble, blackjackSplit, parseFourInARow, fourInARowAI, spellFunc, monsterFunc, nameGen, tavernGen, movieFunc, roll_dice, parseChar, parseRoll, critRoll, parseDestiny, parseHex
|
||||
|
||||
from gameLoops import fiar, blackjackLoop, runhex
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
"""A collection of all Gwendolyn functions."""
|
||||
|
||||
__all__ = ["helloFunc", "cap", "imageFunc", "logThis", "findWikiPage", "makeFiles", "emojiToNumber", "fiarReactionTest", "deleteGame", "stopServer", "checkBalance", "giveMoney", "addMoney", "triviaCountPoints", "triviaStart", "triviaAnswer", "blackjackShuffle", "blackjackStart", "blackjackPlayerDrawHand", "blackjackContinue", "blackjackFinish", "blackjackHit", "blackjackStand", "blackjackDouble", "blackjackSplit", "parseFourInARow", "fourInARowAI", "spellFunc", "monsterFunc", "nameGen", "tavernGen", "movieFunc", "roll_dice", "parseChar", "parseRoll", "critRoll", "parseDestiny"]
|
||||
__all__ = ["helloFunc", "cap", "imageFunc", "logThis", "findWikiPage", "makeFiles", "emojiToNumber", "fiarReactionTest", "deleteGame", "stopServer", "checkBalance", "giveMoney", "addMoney", "triviaCountPoints", "triviaStart", "triviaAnswer", "blackjackShuffle", "blackjackStart", "blackjackPlayerDrawHand", "blackjackContinue", "blackjackFinish", "blackjackHit", "blackjackStand", "blackjackDouble", "blackjackSplit", "parseFourInARow", "fourInARowAI", "spellFunc", "monsterFunc", "nameGen", "tavernGen", "movieFunc", "roll_dice", "parseChar", "parseRoll", "critRoll", "parseDestiny","parseHex"]
|
||||
|
||||
from .miscFuncs import helloFunc, cap, imageFunc, logThis, findWikiPage, makeFiles, replaceMultiple, emojiToNumber, fiarReactionTest, deleteGame, stopServer
|
||||
|
||||
from .games import checkBalance, giveMoney, addMoney, triviaCountPoints, triviaStart, triviaAnswer, blackjackShuffle, blackjackStart, blackjackPlayerDrawHand, blackjackContinue, blackjackFinish, blackjackHit, blackjackStand, blackjackDouble, blackjackSplit, parseFourInARow, fourInARowAI
|
||||
from .games import checkBalance, giveMoney, addMoney, triviaCountPoints, triviaStart, triviaAnswer, blackjackShuffle, blackjackStart, blackjackPlayerDrawHand, blackjackContinue, blackjackFinish, blackjackHit, blackjackStand, blackjackDouble, blackjackSplit, parseFourInARow, fourInARowAI, parseHex
|
||||
|
||||
from .lookup import spellFunc, monsterFunc
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
"""Functions for games Gwendolyn can play."""
|
||||
|
||||
__all__ = ["checkBalance", "giveMoney", "addMoney","triviaCountPoints", "triviaStart", "triviaAnswer", "blackjackShuffle", "blackjackStart", "blackjackPlayerDrawHand", "blackjackContinue", "blackjackFinish", "blackjackHit", "blackjackStand", "blackjackDouble", "blackjackSplit", "parseFourInARow", "fourInARowAI"]
|
||||
__all__ = ["checkBalance", "giveMoney", "addMoney","triviaCountPoints", "triviaStart", "triviaAnswer", "blackjackShuffle", "blackjackStart", "blackjackPlayerDrawHand", "blackjackContinue", "blackjackFinish", "blackjackHit", "blackjackStand", "blackjackDouble", "blackjackSplit", "parseFourInARow", "fourInARowAI", "parseHex"]
|
||||
|
||||
from .money import checkBalance, giveMoney, addMoney
|
||||
from .trivia import triviaCountPoints, triviaStart, triviaAnswer
|
||||
from .blackjack import blackjackShuffle, blackjackStart, blackjackPlayerDrawHand, blackjackContinue, blackjackFinish, blackjackHit, blackjackStand, blackjackDouble, blackjackSplit
|
||||
from .fourInARow import parseFourInARow, fourInARowAI
|
||||
from .fourInARow import parseFourInARow, fourInARowAI
|
||||
from .hex import parseHex
|
@ -25,15 +25,17 @@ easy = True
|
||||
def fourInARowStart(channel, user, opponent):
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
|
||||
if user.lower() != opponent.lower():
|
||||
if channel not in data["4 in a row games"]:
|
||||
|
||||
|
||||
if opponent in ["1","2","3","4","5"]:
|
||||
difficulty = int(opponent)
|
||||
diffText = " with difficulty "+opponent
|
||||
opponent = "Gwendolyn"
|
||||
elif opponent.lower() == "gwendolyn":
|
||||
difficulty = 3
|
||||
diffText = " with difficulty 3"
|
||||
opponent = "Gwendolyn"
|
||||
else:
|
||||
try:
|
||||
@ -42,6 +44,7 @@ def fourInARowStart(channel, user, opponent):
|
||||
except:
|
||||
# Opponent is another player
|
||||
difficulty = 5
|
||||
difftext = ""
|
||||
|
||||
board = [ [ 0 for i in range(columnCount) ] for j in range(rowCount) ]
|
||||
players = [user,opponent]
|
||||
@ -52,7 +55,7 @@ def fourInARowStart(channel, user, opponent):
|
||||
|
||||
with open("resources/games/games.json", "w") as f:
|
||||
json.dump(data,f,indent=4)
|
||||
|
||||
|
||||
fourInARowDraw.drawImage(channel)
|
||||
|
||||
gwendoTurn = False
|
||||
@ -60,7 +63,7 @@ def fourInARowStart(channel, user, opponent):
|
||||
if players[0] == "Gwendolyn":
|
||||
gwendoTurn = True
|
||||
|
||||
return "Started game against "+opponent+". It's "+players[0]+"'s turn", True, False, False, gwendoTurn
|
||||
return "Started game against "+opponent+diffText+". It's "+players[0]+"'s turn", True, False, False, gwendoTurn
|
||||
else:
|
||||
return "There's already a 4 in a row game going on in this channel", False, False, False, False
|
||||
else:
|
||||
@ -70,13 +73,13 @@ def fourInARowStart(channel, user, opponent):
|
||||
def placePiece(channel : str,player : int,column : int):
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
|
||||
if channel in data["4 in a row games"]:
|
||||
board = data["4 in a row games"][channel]["board"]
|
||||
|
||||
board = placeOnBoard(board,player,column)
|
||||
|
||||
|
||||
|
||||
|
||||
if board != None:
|
||||
data["4 in a row games"][channel]["board"] = board
|
||||
turn = (data["4 in a row games"][channel]["turn"]+1)%2
|
||||
@ -95,8 +98,9 @@ def placePiece(channel : str,player : int,column : int):
|
||||
data["4 in a row games"][channel]["win coordinates"] = winCoordinates
|
||||
|
||||
message = data["4 in a row games"][channel]["players"][won-1]+" won."
|
||||
winAmount = data["4 in a row games"][channel]["difficulty"] * 5
|
||||
if data["4 in a row games"][channel]["players"][won-1] != "Gwendolyn":
|
||||
message += " Adding 20 GwendoBucks to their account."
|
||||
message += " Adding "+str(winAmount)+" GwendoBucks to their account."
|
||||
elif 0 not in board[0]:
|
||||
gameWon = True
|
||||
message = "It's a draw!"
|
||||
@ -112,14 +116,14 @@ def placePiece(channel : str,player : int,column : int):
|
||||
if data["4 in a row games"][channel]["players"][turn] == "Gwendolyn":
|
||||
logThis("It's Gwendolyn's turn")
|
||||
gwendoTurn = True
|
||||
|
||||
|
||||
fourInARowDraw.drawImage(channel)
|
||||
return message, True, True, gameWon, gwendoTurn
|
||||
else:
|
||||
return "There isn't any room in that column", True, True, False, False
|
||||
else:
|
||||
return "There's no game in this channel", False, False, False, False
|
||||
|
||||
|
||||
# Returns a board where a piece has been placed in the column
|
||||
def placeOnBoard(board,player,column):
|
||||
placementx, placementy = -1, column
|
||||
@ -145,7 +149,7 @@ def parseFourInARow(command, channel, user):
|
||||
if len(commands) == 1: # if the commands is "!fourinarow start", the opponent is Gwendolyn
|
||||
commands.append("3")
|
||||
return fourInARowStart(channel,user,commands[1]) # commands[1] is the opponent
|
||||
|
||||
|
||||
# Stopping the game
|
||||
elif commands[0] == "stop":
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
@ -155,7 +159,7 @@ def parseFourInARow(command, channel, user):
|
||||
return "Ending game.", False, False, True, False
|
||||
else:
|
||||
return "You can't end a game where you're not a player.", False, False, False, False
|
||||
|
||||
|
||||
# Placing manually
|
||||
elif commands[0] == "place":
|
||||
try:
|
||||
@ -228,7 +232,7 @@ def fourInARowAI(channel):
|
||||
logThis("Figuring out best move")
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
|
||||
board = data["4 in a row games"][channel]["board"]
|
||||
player = data["4 in a row games"][channel]["players"].index("Gwendolyn")+1
|
||||
difficulty = data["4 in a row games"][channel]["difficulty"]
|
||||
@ -268,7 +272,7 @@ def AICalcPoints(board,player):
|
||||
for place in range(columnCount-3):
|
||||
window = rowArray[place:place+4]
|
||||
score += evaluateWindow(window,player,otherPlayer)
|
||||
|
||||
|
||||
# Checks Vertical
|
||||
for column in range(columnCount):
|
||||
columnArray = [int(i[column]) for i in list(board)]
|
||||
@ -288,7 +292,7 @@ def AICalcPoints(board,player):
|
||||
window = [board[row][place],board[row+1][place-1],board[row+2][place-2],board[row+3][place-3]]
|
||||
score += evaluateWindow(window,player,otherPlayer)
|
||||
|
||||
|
||||
|
||||
## Checks if anyone has won
|
||||
#won = isWon(board)[0]
|
||||
|
||||
@ -313,7 +317,7 @@ def evaluateWindow(window,player,otherPlayer):
|
||||
|
||||
def minimax(board, depth, player , originalPlayer, alpha, beta, maximizingPlayer):
|
||||
terminal = ((isWon(board)[0] != 0) or (0 not in board[0]))
|
||||
# The depth is how many moves ahead the computer checks. This value is the difficulty.
|
||||
# The depth is how many moves ahead the computer checks. This value is the difficulty.
|
||||
if depth == 0 or terminal:
|
||||
points = AICalcPoints(board,originalPlayer)
|
||||
return points
|
||||
@ -343,4 +347,3 @@ def minimax(board, depth, player , originalPlayer, alpha, beta, maximizingPlayer
|
||||
if beta <= alpha:
|
||||
break
|
||||
return value
|
||||
|
||||
|
@ -65,7 +65,7 @@ def hexStart(channel, user, opponent):
|
||||
return "That difficulty doesn't exist", False, False, False, False
|
||||
else:
|
||||
# Opponent is another player
|
||||
difficulty = "NA"
|
||||
difficulty = None
|
||||
|
||||
board = [ [ 0 for i in range(columnCount) ] for j in range(rowCount) ]
|
||||
players = [user,opponent]
|
||||
|
19
gameLoops.py
19
gameLoops.py
@ -14,7 +14,7 @@ async def deleteMessage(imageLocation,channel):
|
||||
await oldImage.delete()
|
||||
except:
|
||||
oldImage = ""
|
||||
|
||||
|
||||
return oldImage
|
||||
|
||||
# Runs Hex
|
||||
@ -23,7 +23,7 @@ async def runhex(channel,command,user):
|
||||
response, showImage, deleteImage, gameDone, gwendoTurn = parseHex(command,str(channel),user)
|
||||
except:
|
||||
logThis("Error parsing command (error code 1510)")
|
||||
|
||||
|
||||
await channel.send(response)
|
||||
logThis(response,str(channel))
|
||||
if showImage:
|
||||
@ -49,7 +49,7 @@ async def runhex(channel,command,user):
|
||||
else:
|
||||
with open("resources/games/oldImages/hex"+str(channel), "w") as f:
|
||||
f.write(str(oldImage.id))
|
||||
|
||||
|
||||
if gameDone:
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
@ -77,7 +77,7 @@ async def fiar(channel,command,user):
|
||||
response, showImage, deleteImage, gameDone, gwendoTurn = parseFourInARow(command,str(channel),user)
|
||||
except:
|
||||
logThis("Error parsing command (error code 1410)")
|
||||
|
||||
|
||||
await channel.send(response)
|
||||
logThis(response,str(channel))
|
||||
if showImage:
|
||||
@ -106,7 +106,7 @@ async def fiar(channel,command,user):
|
||||
reactions = ["1️⃣","2️⃣","3️⃣","4️⃣","5️⃣","6️⃣","7️⃣"]
|
||||
for reaction in reactions:
|
||||
await oldImage.add_reaction(reaction)
|
||||
|
||||
|
||||
except:
|
||||
logThis("Image deleted before I could react to all of them")
|
||||
|
||||
@ -130,7 +130,7 @@ async def fiar(channel,command,user):
|
||||
try:
|
||||
with open("resources/games/oldImages/fourInARow"+str(channel), "r") as f:
|
||||
oldImage = await channel.fetch_message(int(f.read()))
|
||||
|
||||
|
||||
await oldImage.delete()
|
||||
except:
|
||||
logThis("The old image was already deleted")
|
||||
@ -161,7 +161,7 @@ async def blackjackLoop(channel,gameRound,gameID):
|
||||
oldImage = await channel.send(file = discord.File("resources/games/blackjackTables/blackjackTable"+str(channel)+".png"))
|
||||
with open("resources/games/oldImages/blackjack"+str(channel), "w") as f:
|
||||
f.write(str(oldImage.id))
|
||||
|
||||
|
||||
try:
|
||||
if allStanding:
|
||||
await asyncio.sleep(5)
|
||||
@ -169,10 +169,10 @@ async def blackjackLoop(channel,gameRound,gameID):
|
||||
await asyncio.sleep(120)
|
||||
except:
|
||||
logThis("Loop "+str(gameRound)+" interrupted (error code 1321)")
|
||||
|
||||
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
|
||||
if str(channel) in data["blackjack games"]:
|
||||
realRound = data["blackjack games"][str(channel)]["round"]
|
||||
realGameID = data["blackjack games"][str(channel)]["id"]
|
||||
@ -191,4 +191,3 @@ async def blackjackLoop(channel,gameRound,gameID):
|
||||
logThis("Ending loop on round "+str(gameRound),str(channel))
|
||||
else:
|
||||
logThis("Ending loop on round "+str(gameRound),str(channel))
|
||||
|
||||
|
Reference in New Issue
Block a user