Requesting following features

I'm thinking that debugging the senate outcome classes will take painfully long if we do it in this thread, one issue, one error and one exception at a time! :lol: (Just remember to keep me up-to-date with the very latest version of the senate missions module, otherwise it may prove impossible!)
 
urg I haven't even started work yet... Btw I love the historical cities, however I have noticed something (can't be to sure as I wasn't checking exact coords), the ai isn't founding directly on historical sities. I guess this is intended as they still found where there is a name but within the BFC or what ever (only seems to be the ajacent tile :p). Just thought I would warn you just in case it is a underlining problem but I am sure it was intended. But yeah I played my tester as germania (stupid calendar means I can't find out what happens next :p) and it was really cool founding cities in the right places (and knowing where the ai's cities are :lol:) I founded brussels (can't remember the latin name) and then Iberian tribes razed it it was my fault I left it undefended :p, so I refounded (still kept the name, which is good) and then lead a campaign into iberia... Then the exception came :(
 
Yeah, you might wanna reconsider some of your design on those historical settlements. You probably wanna double-check all the city coordinates against the data you supplied, to make sure that the script really does what it sets out to do. (I never tested any of it in a real game. This is your duty.)
 
It shouldn't be to be to be honest, it allows some variation, the romans founded a city one tile south of it's definition in game and it was a much better site :p
 
Ok I am having a personal programming problem and I cannot work out why...

basically I am programming the computer to play chess, the first step is to get a list of all possible moves it can make. while making a list of all possible interactions with other pieces (to be checked to see if they are a move) I get an error, which if I try to replicate in idle works perfectly...

Code:
    def getOffence(self):
        black = list()
        white = list()
        moves = dict()
        for x in range(Board().lenY):
            for y in self.game[x]:
                if y[0].keys()[0].Name != None:
                    if y[0][y[0].keys()[0]] == "w":
                        white.append(y)
                    else:
                        black.append(y)
                else:
                    continue
        for x in white:
            for y in black:
                moves[x[1]] = []
                moves[x].append(y[1]) # problem
        return moves
if you were wondering what x and y are in the error line then this is it

[{<__main__.Rook instance at 0x01F1F9B8>: 'b'}, (1, 1)] #y
[{<__main__.Pawn instance at 0x01F143C8>: 'w'}, (1, 7)] #x

do what this should be doing is making x[1] the key, which works and then making it a list that works. When trying to allocate y[1] to the list it fails giving me this usefull piece of information:

Traceback (most recent call last):
File "<pyshell#35>", line 1, in <module>
print AI(gameBoard).getOffence()
File "C:\Users\Jamie\Documents\Python Tutorial stuff\PickleJars\Chess.py", line 90, in getOffence
moves[x].append(y[1])
TypeError: unhashable type: 'list'

to futher express the problem this is what it ends at

{(1, 7): []}

surely moves[x].append(y[1]) should end with this:

{(1, 7): [(1, 1)]}

and this works in idle but not inside the for loop????

what does unhashable mean? what on earth is going on

full code:
Spoiler :

Code:
##Chess##
from PickleJar import *
##Classes, Functions, Constants##
#Classes
class Piece:
    def __init__(self):
        self.Name = None
        self.sName = "0"
        self.Value = 0
        self.Moves = {"y" : 0, "x" : 0, "xy" : 0, "-yx" : 0}
        self.Number = 0

class King(Piece):
    def __init__(self):
        self.Name = "King"
        self.sName = "Ki"
        self.Value = 100
        self.Moves = {"y" : 1, "x" : 1, "xy" : 1, "-yx" : 1}
        self.Number = 1

class Queen(Piece):
    def __init__(self):
        self.Name = "Queen"
        self.sName = "Q"
        self.Value = 20
        self.Moves = {"y" : 2, "x"  :2, "xy" : 2, "-yx" : 2}
        self.Number = 1

class Rook(Piece):
    def __init__(self):
        self.Name = "Rook"
        self.sName = "R"
        self.Value = 10
        self.Moves = {"y" : 2, "x" : 2, "xy" : 0, "-yx" : 0}
        self.Number = 2

class Bishop(Piece):
    def __init__(self):
        self.Name = "Bishop"
        self.sName = "B"
        self.Value = 10
        self.Moves = {"y" : 0, "x" : 0, "xy" : 2, "-yx" : 2}
        self.Number = 2

class Knight(Piece):
    def __init__(self):
        self.Name = "Knight"
        self.sName = "Kn"
        self.Value = 8
        self.Moves = {"kX" : {"x" : 2, "y" : 1}, "kY" : {"x" : 1, "y" : 2}}
        self.Number = 2

class Pawn(Piece):
    def __init__(self):
        self.Name = "Pawn"
        self.sName = "P"
        self.Value = 1
        self.Moves = {"y" : 1, "x" : 0, "xy" : 0, "-yx" : 0}
        self.Number = 8

class Board:
    def __init__(self):
        self.lenX = 8
        self.lenY = 8
        self.iTiles = self.lenX * self.lenY

class AI:
    def __init__(self, game):
        self.game = game

    def getAIMove(self):
        pass

    def getOffence(self):
        black = list()
        white = list()
        moves = dict()
        for x in range(Board().lenY):
            for y in self.game[x]:
                if y[0].keys()[0].Name != None:
                    if y[0][y[0].keys()[0]] == "w":
                        white.append(y)
                    else:
                        black.append(y)
                else:
                    continue
        for x in white:
            for y in black:
                moves[x[1]] = []
                moves[x].append(y[1])
        return moves

    def getDefence(self):
        pass

    def getRandSafe(self):
        pass

    def evalMoves(self, lMoves):
        pass

#Functions
def setBoard():
    gameY = [range(1, (Board().lenX + 1)), \
                   range(1, (Board().lenX + 1)), \
                   range(1, (Board().lenX + 1)), \
                   range(1, (Board().lenX + 1)), \
                   range(1, (Board().lenX + 1)), \
                   range(1, (Board().lenX + 1)), \
                   range(1, (Board().lenX + 1)), \
                   range(1, (Board().lenX + 1))\
                 ]
    n = 0
    iNumPawn = 0
    iNumKing = 0
    iNumQueen = 0
    iNumRook = 0
    iNumBishop = 0
    iNumKnight = 0
    while n < Board().lenX:
        (gameY[1])[n] = [{Pawn(): "b"}, 0]
        (gameY[6])[n] = [{Pawn(): "w"}, 0]
        iNumPawn += 2
        n += 1
    n = 0
    while n < Board().lenY:
        if n == 0:
            (gameY[n])[0] = [{Rook() : "b"}, 0]
            (gameY[n])[1] = [{Knight() : "b"}, 0]
            (gameY[n])[2] = [{Bishop() : "b"}, 0]
            (gameY[n])[3] = [{Queen() : "b"}, 0]
            (gameY[n])[4] = [{King() : "b"}, 0]
            (gameY[n])[5] = [{Bishop() : "b"}, 0]
            (gameY[n])[6] = [{Knight() : "b"}, 0]
            (gameY[n])[7] = [{Rook() : "b"}, 0]
        else:
            (gameY[n])[0] = [{Rook() : "w"}, 0]
            (gameY[n])[1] = [{Knight() : "w"}, 0]
            (gameY[n])[2] = [{Bishop() : "w"}, 0]
            (gameY[n])[3] = [{Queen() : "w"}, 0]
            (gameY[n])[4] = [{King() : "w"}, 0]
            (gameY[n])[5] = [{Bishop() : "w"}, 0]
            (gameY[n])[6] = [{Knight() : "w"}, 0]
            (gameY[n])[7] = [{Rook() : "w"}, 0]
        iNumKing += 1
        iNumQueen += 1
        iNumRook += 2
        iNumBishop += 2
        iNumKnight += 2
        n += 7
    n = 2
    m = 0
    while n < Board().lenY - 2:
        while m < Board().lenX:
            (gameY[n])[m] = [{Piece() : "0"}, 0]
            m += 1
        m = 0
        n += 1
    x = 0
    y = 0
    while y < Board().lenY:
        while x < Board().lenX:
            (gameY[y])[x][1] = (x + 1, y + 1)
            x += 1
        x = 0
        y += 1
    gameX = 0
    for iX in gameY:
        gameX += 1
    if iNumPawn == Pawn().Number * 2 and iNumKnight ==Knight().Number * 2 and iNumRook == Rook().Number * 2 and iNumBishop == Bishop().Number * 2 and iNumQueen == Queen().Number * 2 and iNumKing == King().Number * 2:
        if len(gameY) * gameX == Board().iTiles:
            return gameY

def displayGame(game):
    n = 9
    game.reverse()
    for y in gameBoard:
        n += -1
        print n, str({y[0][0].keys()[0].sName : y[0][0][y[0][0].keys()[0]]})+",",\
              str({y[1][0].keys()[0].sName : y[1][0][y[1][0].keys()[0]]})+",",\
              str({y[2][0].keys()[0].sName : y[2][0][y[2][0].keys()[0]]})+",",\
              str({y[3][0].keys()[0].sName : y[3][0][y[3][0].keys()[0]]})+",",\
              str({y[4][0].keys()[0].sName : y[4][0][y[4][0].keys()[0]]})+",",\
              str({y[5][0].keys()[0].sName : y[5][0][y[5][0].keys()[0]]})+",",\
              str({y[6][0].keys()[0].sName : y[6][0][y[6][0].keys()[0]]})+",", \
              {y[7][0].keys()[0].sName : y[7][0][y[7][0].keys()[0]]}
    print "        1          2            3            4            5           6           7            8"
    game.reverse()
    
def displayMessage(wPiece, lPiece, wPlayer, lPlayer, check = False, checkmate = False, stalemate = None):
    if check:
        print lPlayer, "is in check!"
    elif checkmate:
        print lPlayer, "is in check mate!"
        print wPlayer, "has won the game!"
    elif stalemate:
        print "A stalemate has occured, game ends!"
    else:   
        print wPlayer + "'s", wPiece, "has taken", lPlayer + "'s", lPiece + "!"

def checkMove(sTile, eTile, ePiece, ai = False): #add checkmate/check/stalemate functionality
    sX, sY = getCoords(sTile)
    eX, eY = getCoords(eTile)
    xMove = eX - sX
    yMove = eY - sY
    eMoves = ePiece.Moves
    if ePiece.Name == "King":
        if xMove == eMoves["x"] or xMove == -1 * eMoves["x"] :
            if yMove == eMoves["y"] or yMove == -1 * eMoves["y"]:
                if hasBlack(sTile) and not hasBlack(eTile):
                    return True
                elif hasWhite(sTile) and not hasWhite(eTile):
                    return True
                else:
                    return False
            else:
                return False
        else:
            return False
    elif ePiece.Name == "Queen":
        if (xMove == yMove * -1) or (xMove == yMove): 
            if hasBlack(sTile) and not hasBlack(eTile):
                if (xMove > 0 and yMove > 0):
                    a = splitMoves(sTile, eTile)
                elif (xMove < 0 and yMove < 0):
                    a = splitMoves(eTile, sTile)
                elif (xMove > 0 and yMove < 0):
                    a = splitMoves(sTile, eTile, True)
                else:
                    a = splitMoves(eTile, sTile, True)
                for n in a:
                    sTile = getGameInstance(n, gameBoard)
                    if hasBlack(sTile) or hasWhite(sTile):
                        return False
                return True
            elif hasWhite(sTile) and not hasWhite(eTile):
                if (xMove > 0 and yMove > 0):
                    a = splitMoves(sTile, eTile)
                elif (xMove < 0 and yMove < 0):
                    a = splitMoves(eTile, sTile)
                elif (xMove > 0 and yMove < 0):
                    a = splitMoves(sTile, eTile, True)
                else:
                    a = splitMoves(eTile, sTile, True)
                for n in a:
                    sTile = getGameInstance(n, gameBoard)
                    if hasWhite(sTile) or hasBlack(sTile):
                        return False
                return True
            else:
                return False
        elif (xMove == 0 or yMove == 0):
            if hasBlack(sTile) and not hasBlack(eTile):
                if xMove < 0 or yMove < 0:
                    a = splitMoves(eTile, sTile)
                else:
                    a  = splitMoves(sTile, eTile)
                for n in a:
                    sTile = getGameInstance(n, gameBoard)
                    if  hasWhite(sTile) or hasBlack(sTile):
                        return False
                return True
            elif hasWhite(sTile) and not hasWhite(eTile):
                if xMove < 0 or yMove < 0:
                    a = splitMoves(eTile, sTile)
                else:
                    a  = splitMoves(sTile, eTile)
                for n in a:
                    sTile = getGameInstance(n, gameBoard)
                    if  hasWhite(sTile) or hasBlack(sTile):
                        return False
                return True
            else:
                return False
        else:
            return False
    elif ePiece.Name == "Knight":
        if (xMove ==1 and yMove == 2) or (xMove == -1 and yMove == 2) or (xMove == 1 and yMove == -2) or (xMove == -1 and yMove == -2) or (xMove == 2 and yMove == 1) or (xMove == 2 and yMove == -1) or (xMove == -2 and yMove == 1) or (xMove == -2 and yMove == -1):
            if hasBlack(sTile) and not hasBlack(eTile):
                return True
            elif hasWhite(sTile) and not hasWhite(eTile):
                return True
            else:
                return False
        else:
            return False
    elif ePiece.Name == "Rook":
        if xMove == 0 or yMove == 0:
            if hasBlack(sTile) and not hasBlack(eTile):
                if xMove < 0 or yMove < 0:
                    a = splitMoves(eTile, sTile)
                else:
                    a  = splitMoves(sTile, eTile)
                for n in a:
                    sTile = getGameInstance(n, gameBoard)
                    if  hasWhite(sTile) or hasBlack(sTile):
                        return False
                return True
            elif hasWhite(sTile) and not hasWhite(eTile):
                if xMove < 0 or yMove < 0:
                    a = splitMoves(eTile, sTile)
                else:
                    a  = splitMoves(sTile, eTile)
                for n in a:
                    sTile = getGameInstance(n, gameBoard)
                    if  hasWhite(sTile) or hasBlack(sTile):
                        return False
                return True
            else:
                return False
        else:
            return False
    elif ePiece.Name == "Bishop":
        if (xMove != 0 and yMove != 0) and (xMove == yMove or xMove * -1 == yMove):
            if hasBlack(sTile) and not hasBlack(eTile):
                if (xMove > 0 and yMove > 0):
                    a = splitMoves(sTile, eTile)
                elif (xMove < 0 and yMove < 0):
                    a = splitMoves(eTile, sTile)
                elif (xMove > 0 and yMove < 0):
                    a = splitMoves(sTile, eTile, True)
                else:
                    a = splitMoves(eTile, sTile, True)
                for n in a:
                    sTile = getGameInstance(n, gameBoard)
                    if hasWhite(sTile) or hasBlack(sTile):
                        return False
                return True
            elif hasWhite(sTile) and not hasWhite(eTile):
                if (xMove > 0 and yMove > 0):
                    a = splitMoves(sTile, eTile)
                elif (xMove < 0 and yMove < 0):
                    a = splitMoves(eTile, sTile)
                elif (xMove > 0 and yMove < 0):
                    a = splitMoves(sTile, eTile, True)
                else:
                    a = splitMoves(eTile, sTile, True)
                for n in a:
                    sTile = getGameInstance(n, gameBoard)
                    if  not (hasWhite(sTile) or hasBlack(sTile)):
                        return True
                return False
            else:
                return False
        else:
            return False
    elif ePiece.Name == "Pawn":
        if xMove == eMoves["x"]:
            if (yMove == eMoves["y"] and not ai) or (ai and yMove * -1 == eMoves["y"]):
                if hasBlack(sTile) and not hasBlack(eTile):
                    if hasBlack(sTile) and not hasWhite(eTile):
                        return True
                    else:
                        return False
                elif hasWhite(sTile) and not hasWhite(eTile):
                    if hasWhite(sTile) and not hasBlack(eTile):
                        return True
                    else:
                        return False
                else:
                    return False
            elif (yMove == 2 and not ai) or (yMove * -1 == 2 and ai):
                if hasBlack(sTile) and not hasBlack(eTile):
                    if hasBlack(sTile) and not hasWhite(eTile):
                        if getCoords(sTile)[1] == 2:
                            if yMove < 0:
                                a = splitMoves(eTile, sTile)
                            else:
                                a =splitMoves(sTile, eTile)
                            for n in a:
                                sTile = getGameInstance(n, gameBoard)
                                if hasWhite(sTile) or hasBlack(sTile):
                                    return False
                                return True
                        else:
                            return False
                    else:
                        return false
                elif hasWhite(sTile) and not hasWhite(eTile):
                    if hasWhite(sTile) and not hasBlack(eTile):
                        if getCoords(sTile)[1] == 7:
                            if yMove < 0:
                                a = splitMoves(eTile, sTile)
                            else:
                                a =splitMoves(sTile, eTile)
                            for n in a:
                                sTile = getGameInstance(n, gameBoard)
                                if hasWhite(sTile) or hasBlack(sTile):
                                    return False
                                return True
                        else:
                            return False
                    else:
                        return False
            else:
                return False
        elif xMove == 1 or xMove == -1:
            if (yMove == eMoves["y"] and not ai) or (ai and yMove * -1 == eMoves["y"]):
                if hasBlack(sTile) and hasWhite(eTile):
                    return True
                elif hasWhite(sTile) and hasBlack(eTile):
                    return True
                else:
                    return False
            else:
                return False
        else:
            return False
    else:
        return False
def getCoords(Tile):
    Tile = Tile[1]
    return Tile

def getGameInstance(Coords, Game):
    iX, iY = Coords
    return Game[iY - 1][iX - 1]

def splitMoves(sTile, eTile, semiNegative = False):
    """
    When moving forward or right use function as normal, however,
    if left or down reverse the order of sTile and eTile. For
    Diagonals use the same system apart from moving up and to the left
    or down and to the right. These are examples of seminegative values
    and must be supplied with the semiNegative arguement as True.
    Up/Right = sTile, eTile
    Down/Left = eTile, sTile
    Up/Left = sTile, eTile, True
    Down/Right = eTile, sTile, True
    """
    sX, sY = getCoords(sTile)
    eX, eY = getCoords(eTile)
    if not semiNegative:
        xMove = eX - sX
        yMove = eY - sY
    else:
        xMove = eX - sX
        yMove = sY - eY
    split = list()
    if xMove == 0:
        for n in range(1, yMove):
            split.append((sX, sY + n))
    elif yMove == 0:
        for n in range(1, xMove + 1):
            split.append((sX + n, sY))
    else:
        for a in range(1, xMove):
            for b in range(1, yMove):
                split.append((sX + a, sY + b))        
    return split

def hasBlack(Tile):
    """
    Returns True if the piece on the supplied GameInstance is black
    """
    if Tile[0][Tile[0].keys()[0]] == "b":
        return True
    else:
        return False

def hasWhite(Tile):
    """
    Returns True if the piece on the supplied GameInstance is white
    """
    if Tile[0][Tile[0].keys()[0]] == "w":
        return True
    else:
        return False

def SaveLoad(save, name, board = None, move = None):
    """
    To save, enter values in the 2 last arguements, if loading, enter
    (False, name)
    """
    if save:
        saveDict = [board, move]
        PickleJar(saveDict, name + "SaveData.txt")
    else:
        loadDict = OpenPickleJar(name + "SaveData.txt")
        return loadDict

def makeMove(startCoords, endCoords, playerColour, game, player1, ai = False, player2 = "Computer"):
    gameStart = getGameInstance(startCoords, game)
    gameEnd = getGameInstance(endCoords, game)
    movingPiece = gameStart[0].keys()[0]
    if checkMove(gameStart, gameEnd, movingPiece, ai):
        if playerColour == "w" and hasBlack(gameEnd):
            takenPiece = gameEnd[0].keys()[0]
            gameEnd[0] = {movingPiece : playerColour}
            gameStart[0] = {Piece() : "0"}
            displayGame(game)
            print ''
            print player2 + "'s", movingPiece.Name, "has moved to", endCoords 
            displayMessage(movingPiece.Name, takenPiece.Name, player2, player1)
            print ''
        elif playerColour == "b" and hasWhite(gameEnd):
            takenPiece = gameEnd[0].keys()[0]
            gameEnd[0] = {movingPiece : playerColour}
            gameStart[0] = {Piece() : "0"}
            displayGame(game)
            print ''
            print player1 + "'s", movingPiece.Name, "has moved to", endCoords 
            displayMessage(movingPiece.Name, takenPiece.Name, player1, player2)
            print ''
        else:
            gameEnd[0] = {movingPiece : playerColour}
            gameStart[0] = {Piece() : "0"}
            displayGame(game)
            if playerColour == "w":
                print ''
                print player2 + "'s", movingPiece.Name, "has moved to", endCoords
                print ''
            else:
                print ''
                print player1 + "'s", movingPiece.Name, "has moved to", endCoords
                print ''
        return True
    else:
        return False
def checkMate(game, Checkmate): #Do more
    if Checkmate:
        return True
    else:
        return False

def isCheckmate(player): #Do more
    return False

##Game programming##
Loop = True
while Loop:
    gameBoard = setBoard()
    Computer = "Computer"
    Turn = "w"
    Quit = False
    Checkmate = False
    Player = input("Player name (within ''): ")
    try:
        SaveLoad(False, Player)
        load = input("Do you want to load a save (True/False): ")
        if load:
            gameBoard, Turn = SaveLoad(False, Player)
    except IOError:
        None
    displayGame(gameBoard)
    while not Checkmate:
        if Turn == "w":
            #startingTile, endingTile = AI(gameBoard).getAIMove()
            #makeMove(startingTile, endingTile, "w", gameBoard, Player)
            Turn = "b"
        else:
            a = False
            while not a:
                startingTile = input("Enter coords of piece you want to move as (x, y): ")
                endingTile = input("Enter coords of the tile you want to move to as (x, y): ")
                b = makeMove(startingTile, endingTile, "b", gameBoard, Player)
                a = b
                if not a:
                    print "Invalid Move!"
            Turn = "w"
            Quit = input("Do you wish to quit this game? (True/False): ")
            if Quit:
                Save = input("Do you wish to Save? (True/False): ")
                if Save:
                    SaveLoad(True, Player, gameBoard, "w")
                x = 10
                Checkmate = True
        Checkmate = checkMate(gameBoard, Checkmate)
    if isCheckmate(Player):
        displayMessage(None, None, Computer, Player, False, True)
    elif isCheckmate(Computer):
        displayMessage(None, None, Player, Computer, False, True)
    Quit = input("Do you wish to play again? (True/False): ")
    if not Quit:
        Loop = False
        print "Ok!"
 
Well, maybe converting to string or other hashable types shall work. I mean, in line 90 you should try this instead:
moves[x].append(str(y[1]))

I'm writing many Python programs, but never met with this 'unhashable' thingy either, so I can't tell you so much, but give it a try. ;) I tried to do it myself, but I don't know what kind of module is "PickleJar"? Can I use a simple "pickle" or "cPickle" instead?

EDIT: Wait, wait. If the above don't work, here is another solution.
After further reading, i found what hashable means.

A hash function is a function which takes an arbitrary object and
generates an integer from it.

Now a list object is unhashable, so it can't generate integer from that (same applies on dictionaries)
Try this code if the above one don't work:

moves[x].append(hash(y[1]))

The built-in hash function shall do the trick. ;)


EDIT2:
The above things absolutely won't work.
Sorry, I tried everything but you may try exceptions. ;)
Code:
        for x in white:
            for y in black:
                moves[x[1]] = []
                try:
                    moves[x].append(y[1]) # problem
                except TypeError:
                    print ""
        return moves

I'm sorry if I couldn't be useful, but I don't really know why do sequences becomes "unhashables". Ask Guido van Rossum for details. ;)

[By the way, I managed to test your program, and I think I can give you a hint with the name of the player.
You should use "raw_input()" instead "input()". That is because the "input()" function ONLY accepts Python-syntax correct variables (integers, booleans, and quoted strings), and "raw_input()" accepts everything (without quotations(!)) not limited to integers and booleans (or quoted strings)

You may not understang me. I mean replace this (line 539):
Player = input("Player name (within ''): ")
with this:
Player = raw_input("Player name: ")
]
 
I'm interpreting this like: The name x should be an integer, as it is used for indexing, but you happened to put a list type inside the white list. If you add a "print x" statement before the troublesome line you might catch the culprit. And if I'm right, then you could add more print statements along your script to catch where the error originates. Because it does seem that you accidentally end up putting a list where there really should be a integer. Just my take, anyways.
 
welll I did prints and it worked as it should in idle but just not in the code, What did you think of the board? I'm pretty proud of the work so far! all it should be doing is setting the dictionary key as a tuple (x, y) and then add the coords of black pieces to it's list, I fixed it by doing this:
Code:
black2 = list()
for x in black:
       black2.append(x[1])
black = black2

for x in white:
       moves[x[1]] = [black]

that works fine and that is what I intended, but I am so confused why the original solution didn't work?

and thanks about the input... surely it should be player = str(raw_input(...)) # yes it should :p!
ahhhh PickleJar are my own pickle based functions for the saveGame :p
 
PickleJar =

Code:
import pickle

##PickleJar##
def OpenPickleJar(name):
    pjo = open(name, "r")
    read = pjo.read()
    PJO = pickle.loads(read)
    return PJO
def PickleJar(variable, name):
    pj = open(name ,"w")
    pj.write(pickle.dumps(variable))
    pj.close

and the solution I posted returns this (this is what I needed :p):
Spoiler :

{(2, 7): [[(1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 1), (7, 1), (8, 1), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (7, 2), (8, 2)]], (4, 7): [[(1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 1), (7, 1), (8, 1), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (7, 2), (8, 2)]], (6, 7): [[(1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 1), (7, 1), (8, 1), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (7, 2), (8, 2)]], (6, 8): [[(1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 1), (7, 1), (8, 1), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (7, 2), (8, 2)]], (4, 8): [[(1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 1), (7, 1), (8, 1), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (7, 2), (8, 2)]], (2, 8): [[(1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 1), (7, 1), (8, 1), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (7, 2), (8, 2)]], (5, 7): [[(1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 1), (7, 1), (8, 1), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (7, 2), (8, 2)]], (7, 7): [[(1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 1), (7, 1), (8, 1), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (7, 2), (8, 2)]], (3, 8): [[(1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 1), (7, 1), (8, 1), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (7, 2), (8, 2)]], (1, 8): [[(1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 1), (7, 1), (8, 1), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (7, 2), (8, 2)]], (8, 8): [[(1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 1), (7, 1), (8, 1), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (7, 2), (8, 2)]], (8, 7): [[(1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 1), (7, 1), (8, 1), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (7, 2), (8, 2)]], (1, 7): [[(1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 1), (7, 1), (8, 1), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (7, 2), (8, 2)]], (3, 7): [[(1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 1), (7, 1), (8, 1), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (7, 2), (8, 2)]], (7, 8): [[(1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 1), (7, 1), (8, 1), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (7, 2), (8, 2)]], (5, 8): [[(1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 1), (7, 1), (8, 1), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (7, 2), (8, 2)]]}


what are unhashables though and why work in idle but not in code?
 
I commented out the PickleJar parts, so the game started.

btw, IDLE is buggy. It is written in Tkinter which is if overused becomes buggy. It makes some local variables global and such other stupidity. Use Notepad++ instead. But if you like it, restart IDLE, and it'll give you back valid (and for us, wrong) data. I know this, I'm writing a game too, and it always returned stupid values after extensive use. :crazyeye: Restarting it usually solves the problem.

Unhashables are the following sequences: list, tuple, dictionary (maybe there are more, but I can't say you any more ;))

But for the main problem (the hashing-thing), I have no idea. :dunno:
 
what game are you making and what did you think of my code :p

Yeah my code is now:
Code:
    def getOffence(self):
        black = list()
        white = list()
        moves = dict()
        for x in range(Board().lenY):
            for y in self.game[x]:
                if y[0].keys()[0].Name != None:
                    if y[0][y[0].keys()[0]] == "w":
                        white.append(y)
                    else:
                        black.append(y)
                else:
                    continue
##        for x in white:
##            for y in black:
##                moves[x[1]] = []
##                moves[x].append(y[1])
##        return moves
        black2 = list()
        for x in black:
            black2.append(x[1])
        black = black2
        for x in white:
            moves[x[1]] = [black]
        moves2 = dict()
        for x in moves:
            for y in moves[x]:
                for a in y:
                    if checkMove(getGameInstance(x, self.game), getGameInstance(a, self.game), getGameInstance(x, self.game)[0].keys()[0], True):
                        moves2[x] = [a]
        moves = moves2
        return moves
this of course returns {} as non of the moves can be made at the start of the game, gotta move some pieces around to see if it really works :p

edit:
if I move the rook to right infront of two pawns
Spoiler :

8 {'R': 'w'}, {'Kn': 'w'}, {'B': 'w'}, {'Q': 'w'}, {'Ki': 'w'}, {'B': 'w'}, {'Kn': 'w'}, {'R': 'w'}
7 {'P': 'w'}, {'P': 'w'}, {'P': 'w'}, {'P': 'w'}, {'P': 'w'}, {'P': 'w'}, {'P': 'w'}, {'P': 'w'}
6 {'0': '0'}, {'R': 'b'}, {'0': '0'}, {'0': '0'}, {'0': '0'}, {'0': '0'}, {'0': '0'}, {'0': '0'}
5 {'0': '0'}, {'0': '0'}, {'0': '0'}, {'0': '0'}, {'0': '0'}, {'0': '0'}, {'0': '0'}, {'0': '0'}
4 {'P': 'b'}, {'0': '0'}, {'0': '0'}, {'0': '0'}, {'0': '0'}, {'0': '0'}, {'0': '0'}, {'0': '0'}
3 {'0': '0'}, {'0': '0'}, {'0': '0'}, {'0': '0'}, {'0': '0'}, {'0': '0'}, {'0': '0'}, {'0': '0'}
2 {'0': '0'}, {'P': 'b'}, {'P': 'b'}, {'P': 'b'}, {'P': 'b'}, {'P': 'b'}, {'P': 'b'}, {'P': 'b'}
1 {'0': '0'}, {'Kn': 'b'}, {'B': 'b'}, {'Q': 'b'}, {'Ki': 'b'}, {'B': 'b'}, {'Kn': 'b'}, {'R': 'b'}
1 2 3 4 5 6 7 8

Jamie's Rook has moved to (2, 6)


and this gave me back these as moves for the AI which is correct :p

{(3, 7): [(2, 6)], (1, 7): [(2, 6)]}

whoop!
 
what game are you making and what did you think of my code :p

I'm writing a Civilization-like game in Python. Looks good so far. I call it PyVilization. I don't use as many classes as you do, but is not a problem. I only afraid of using so many global variables. (I still use way too many.) If you're interested more in my Pyv game, pm me (I will send screenies of the current version), I don't want to garbage this thread. ;)

You code is complicated, really. But great, you learnt object-oriented progs very well.:goodjob: I wish you good luck to solve that problem. What Baldyr says can have sense, as indexes can't be strings ONLY integers. :think: I shall take a look at that tomorrow...
 
well the fix I am using is fine for the moment but it is odd... yeah I mean if you print gameBoard you can actually work out how the code works... (it's a huge mess, the displayGame(game) function orders it to be readable..) as you can see all the class instances, coords, piece colours. I know the code is very complicated (and I get lost in it :p) but it works perfectly :D and I love it :lol:

Yeah your game sounds awesome, I'll PM you about it in the morning (if I get time)!
 
right these are the rules on calendar

Everything bigger than 12 has to be divisible by 12, because with increments bigger than one year, the game can only deal with whole years.
For increments lower than 12, they have to be either months (1), seasons (3) or half years (6), else it will probably break too.
 
in this code you posted:
Code:
	def cannotFoundCity(self,argsList):
		iPlayer, iPlotX, iPlotY = argsList
		return ( self.cities.isInvalidSite(iPlayer, (iPlotX, iPlotY))
		         or self.custom.isRestricted(iPlayer, (iPlotX, iPlotY)) )

what would be entered into iPlayer? Integer? if so, what do I do with it:p would I be able to use isHuman(iPlayer)?

edit: I guess instance(iPlayer) would work :p
 
heres the resticted player code!
Code:
def isWithin(tCoords, inCoords):
        """
        inCoords to be supplied as ((x, y), (x, y)), bottomLeft first)
        """
        inCoords1, inCoords2 = inCoords
        if tCoords[0] > inCoords1[0] and tCoords[0] < inCoords2[0]:
                if tCoords[1] > inCoords1[1] and tCoords[1] < inCoords2[1]:
                        return True
        return False

def isInvalidSite(ePlayer, tCoords):
        """
        Called from CvGameUtils.cannotFoundCity().
        Returns False if the city plot or any adjacent plot is found in the city name dictionary.
        Also always returns False if the call concerns the human player.
        Returns True by default if no conditions are met.
        """
        if ( instance(ePlayer) == human()
             or isHistoric(tCoords)
             or isHistoric(checkAdjacent(tCoords)) ):
                return False
        return True

def isRestricted(ePlayer, tCoords):
        if not isHistorical(tCoords) or not isHistoric(checkAdjacent(tCoords)):
                if isWithin(tCoords, restrictedCoords):
                        return True
        return False

with restrictedCoords = ((0, 0), (0, 0)) for the moment :p Will it work?
 
in this code you posted:
Code:
	def cannotFoundCity(self,argsList):
		iPlayer, iPlotX, iPlotY = argsList
		return ( self.cities.isInvalidSite(iPlayer, (iPlotX, iPlotY))
		         or self.custom.isRestricted(iPlayer, (iPlotX, iPlotY)) )

what would be entered into iPlayer? Integer? if so, what do I do with it:p would I be able to use isHuman(iPlayer)?

edit: I guess instance(iPlayer) would work :p
What? iPlayer is the PlayerType, so yes; its a integer value. Sadly you can't use CivPlayer in CvGameUtils because that module doesn't import any of the custom stuff in your mod. But, you can use it in the actual module holding the function you're calling.
 
well after a few mishaps this is the current code
Code:
def isRestricted(ePlayer, tCoords):
        if isHistoric(tCoords) or isHistoric(checkAdjacent(tCoords)):
                return False
        else:
                if isWithin(tCoords, restrictedCoords):
                        return True
                else:
                        return False

Code:
def isWithin(tCoords, inCoords):
        """
        inCoords to be supplied as ((x, y), (x, y)), bottomLeft first)
        """
        inCoords1, inCoords2 = inCoords
        if inCoords1[0] <= tCoords[0] <= inCoords2[0]:
                if inCoords1[1] <= tCoords[1] <= inCoords2[1]:
                        return True
        return False

the rest is the same...

and it works perfectly!!!

Now I have a non python related problem to deal with (to do with custom icons :p)
 
Great! Just an afterthought; your code could be abbreviated like this:
Code:
def isRestricted(ePlayer, tCoords):
        if isHistoric(tCoords) or isHistoric(checkAdjacent(tCoords)):
                return False
        else:
                return isWithin(tCoords, restrictedCoords)
...and I noticed you already got rid of the and clauses in the if statements in isWithin(). :goodjob:

I actually think I'll take some time to write a little order management application for work. For my own use only, and just because it would be fun to write something I can use in my day-to-day real life. :D
 
Back
Top Bottom