1
\$\begingroup\$

Battleship.py

# -*- coding: utf-8 -*-
import numpy
import operator
import commands
import random
import sys
import os
from time import sleep
from grid import grid 
from fleet import fleet 

def setupNavy(setupSelection,gridClass,sortedShipList):
    used="no"
    shipCoordList=[]
    for shipData in sortedShipList:
        shipName=shipData[0]
        shipSize=shipData[1]
        if setupSelection=="manual":
            header= "Ship placement: %s size is: %s\n"%(shipName,shipSize)
            sys.stdout.write(header)
        con="yes"
        while con=="yes": 
            if setupSelection=="manual":
                start=raw_input("Enter start point: ")
            else:
                randomX=random.randrange(0,gridClass.xGridSize)
                randomY=random.randrange(0,gridClass.yGridSize)
                xLetter=gridClass.alphDict[randomX]
                start="%s%d"%(xLetter,randomY)
            coordStatus=gridClass.checkDataPointValue(start)
            if coordStatus=="E":
                con="no"
                if setupSelection=="manual":
                    placement=raw_input("Place Vertical (V) or Horizontal (H): ")
                else:
                    placement=random.choice("VH")
                end=gridClass.determineEndPoint(start,shipSize,placement)
                if end=="F":
                    if setupSelection=="manual":
                        error= "Datapoint: %s will place %s off the grid \n"% (start,shipName)
                        sys.stdout.write(error)
                    used="yes"
                else:
                    shipCoordList=gridClass.determineFullLocation(start,end)
                    gridClass.shipLocationDict[shipName]=shipCoordList
                    for coord in shipCoordList:
                        coordList=coord.split(',')
                        dataPoint="%s%s"%(gridClass.alphDict[int(coordList[0])],coordList[1])
                        coordStatus=gridClass.checkDataPointValue(dataPoint)
                        if coordStatus=='T':
                             if setupSelection=="manual":
                                 error= "Datapoint: %s is already used \n"% dataPoint
                                 sys.stdout.write(error)
                             used="yes" 
                if used=="no":
                    gridClass.gridValuesUsed+=shipCoordList
            else: 
                if setupSelection=="manual":
                    error= "Datapoint: %s is already used \n"% dataPoint
                    sys.stdout.write(error)
                con="yes"
            if used=="yes":
                con="yes"
                used="no"

        os.system('clear')
        gridClass.shipPlacement(start,end,shipCoordList)
        gridDict=gridClass.populateGrid()
        if setupSelection=="manual":
            gridClass.displayGrid()

    sleep(0.25)
    os.system('clear')
    return 

def attackShip(whosTurn,attackerGridClass,defenderGridClass,defenderFleetClass):
    newAttack="Y"    
    numShipsInFleet=len(defenderFleetClass.shipStatusDict)
    while newAttack=="Y":
        if whosTurn=="player":
            attackCoords=raw_input("Input attack coordinates: ")
            xLetter=attackCoords[:1]
            xValue=int((ord(xLetter)%32)-1)
            yValue=int(attackCoords[1:])
            startLocation="%s,%s"%(xValue,yValue)
        else:
            if len(attackerGridClass.attackList)!=0:
                startLocation=random.choice(attackerGridClass.attackList)
                sList=startLocation.split(',')
                start="%s%s"%(attackerGridClass.alphDict[int(sList[0])],sList[1])
                end=''
            else:
                if len(attackerGridClass.searchList)>0:
                    startLocation=random.choice(attackerGridClass.searchList)
                else:
                    startLocation=random.choice(attackerGridClass.validPoints)
        xyList=startLocation.split(',')
        x=int(xyList[0])
        y=int(xyList[1])
        start="%s%s"%(attackerGridClass.alphDict[x],y)
        if startLocation in attackerGridClass.validPoints: attackerGridClass.validPoints.remove(startLocation)
        startList=startLocation.split(',')
        xValue=int(startList[0])
        yValue=int(startList[1])
        if startLocation in attackerGridClass.attackList:
            attackerGridClass.attackList.remove(startLocation)
        if startLocation not in attackerGridClass.hitList and startLocation not in attackerGridClass.missedList:
            newAttack="N"
            print "Attacking at %s (%s)"%(start,startLocation)
            sleep(.75)
            if startLocation in defenderGridClass.gridValuesUsed:
                print "BOOM!! Direct Hit"
                sleep(1.25)
                os.system('clear')
                #hit='■'
                hit='×'
                defenderHit='×'
                #Displays when a enemys ship is hit.
                attackerGridClass.gridValuesAttacked[xValue][yValue]="[%s]"%hit
                #Displays when a ship is hit. shows and x in the place of the ship
                defenderGridClass.gridValues[xValue][yValue]="[%s]"%defenderHit
                attackerGridClass.hitList.append(startLocation)
                for ship, locationList in defenderGridClass.shipLocationDict.iteritems():
                    hitsTaken=0
                    shipSize=defenderFleetClass.shipFleetDict[ship]
                    if defenderFleetClass.shipStatusDict[ship]=="active":
                        for location in locationList:
                            if location in attackerGridClass.hitList:
                                hitsTaken+=1
                        if hitsTaken==shipSize:
                            print "%s sunk a %s"%(whosTurn,ship)
                            sleep(1.25)
                            defenderFleetClass.shipStatusDict[ship]="sunk"
                            defenderFleetClass.numberSunkShips+=1  
                            shipsLeft=numShipsInFleet-defenderFleetClass.numberSunkShips
                attackerGridClass.hitList.append(startLocation)
                if startLocation in attackerGridClass.attackList:
                    attackerGridClass.attackList.remove(startLocation)
                left=x-1
                below=y-1
                right=x+1
                above=y+1
                if left>=0:
                    leftValue="%s,%s"%(left,y)
                    leftLetter="%s%s"%(attackerGridClass.alphDict[left],y)
                    if leftValue not in attackerGridClass.attackList and leftLetter not in attackerGridClass.hitList and leftLetter not in attackerGridClass.missedList:
                        attackerGridClass.attackList.append(leftValue)
                if below>=1 or below==1:
                    belowValue="%s,%s"%(x,below)
                    belowLetter="%s%s"%(attackerGridClass.alphDict[x],below)
                    if belowValue not in attackerGridClass.attackList and belowLetter not in attackerGridClass.hitList and belowLetter not in attackerGridClass.missedList:
                        attackerGridClass.attackList.append(belowValue)
                if right<=(defenderGridClass.xGridSize-1):
                    rightValue="%s,%s"%(right,y)
                    rightLetter="%s%s"%(attackerGridClass.alphDict[right],y)
                    if rightValue not in attackerGridClass.attackList and rightLetter not in attackerGridClass.hitList and rightLetter not in attackerGridClass.missedList:
                       attackerGridClass.attackList.append(rightValue)
                if above<=(defenderGridClass.yGridSize-1) or above==defenderGridClass.yGridSize-1:
                    aboveValue="%s,%s"%(x,above)
                    aboveLetter="%s%s"%(attackerGridClass.alphDict[x],above)
                    if aboveValue not in attackerGridClass.attackList and aboveLetter not in attackerGridClass.hitList and aboveLetter not in attackerGridClass.missedList:
                       attackerGridClass.attackList.append(aboveValue)
            else:
                attackerGridClass.missedList.append(startLocation)
                print "Missed %s %s" % (start,startLocation)
                sleep(1.25)
                os.system('clear')
                attackResult="[M]"
                #miss='Ø'
                miss='ø'
                attackResult="[%s]"%miss
                #attackResult="[M]"
                attackerGridClass.gridValuesAttacked[xValue][yValue]="[%s]"%miss
                attackerGridClass.missedList.append(startLocation)
            if startLocation in attackerGridClass.attackList: attackerGridClass.attackList.remove(startLocation)

        else:
            hitOrMiss="Miss"
            if startLocation in attackerGridClass.hitList:hitOrMiss="HIT" 
            if whosTurn=="player":
                print "You already attacked %s%d which was a %s "%(xLetter,yValue,hitOrMiss)
    if defenderFleetClass.numberSunkShips==numShipsInFleet:
        gameOver(attackerGridClass.gridName)
        displayGameStats()
        sys.exit()
        return
    return 

def determineMaxMoves(xGrid,yGrid,player):
    i=0;turnList=[]
    maxTurns=(xGrid*yGrid)*2
    while i < maxTurns:
        if i%2==0:
            #turnList.append('player')
            turnList.append(player)
        else:
            turnList.append('Joshua')
        i+=1 
    return turnList

def gameOver(winner):
    if winner=="USA":
        print "\n******** %s WINS******** \n" %winner
        #print u'{:─^10}'.format(u'')

        print """
         ____________________________________________
        |* * * * * * * * * * |_______________________|
        |* * * * * * * * * * |_______________________|
        |* * * * * * * * * * |_______________________|
        |* * * * * * * * * * |_______________________|
        |* * * * * * * * * * |_______________________|
        |____________________________________________|
        |____________________________________________|
        |____________________________________________|
        |____________________________________________|
        |____________________________________________|
        """        
    else:
        print "Better luck next time..  %s WINS \n" %winner
        print "GAME OVER"

def displayGameStats():
    print "      Results  \n"

    print "Number of attacks: %s"%enemyGridClass.attackCounter
    print "\n"
    print "%s BATTLEFIELD"% enemyGridClass.gridName
    enemyGridClass.populateGrid()
    enemyGridClass.displayGrid()
    print "\n"
    for shipName,shipStatus in enemyFleetClass.shipStatusDict.iteritems():
        print shipName,shipStatus
    print "\n"
    """
    print "Hits \n"
    for coord in enemyGridClass.hitList:
        coordList=coord.split(',')
        dataPoint="%s%s"%(enemyGridClass.alphDict[int(coordList[1])],coordList[0])
        print "%s " % dataPoint    
    """
    #for coord in enemyGridClass.missedList:
    #    coordList=coord.split(',')
    #    dataPoint="%s%s"%(gridClass.alphDict[int(coordList[1])],coordList[0])
    #    print "Missed: %s " % dataPoint    

    print "%s BATTLEFIELD"% myGridClass.gridName
    myGridClass.populateGrid()
    myGridClass.displayGrid()


    print "\n"
    for shipName,shipStatus in myFleetClass.shipStatusDict.iteritems():
        print shipName,shipStatus
    print "\n"
    """
    print "Hits \n"
    for coord in myGridClass.hitList:
        coordList=coord.split(',')
        dataPoint="%s%s"%(myGridClass.alphDict[int(coordList[1])],coordList[0])
        print "HIt: %s " % dataPoint    

    """

def displayMessage(msg):
    for letter in msg:
        sys.stdout.write(letter)
        sys.stdout.flush()
        sleep(.085)

#######################
#Display welcome message
user=commands.getoutput("whoami")
msg= "Greetings %s  my name is Joshua.. Shall we play a game? " % user
displayMessage(msg)

playGame=raw_input("Y or N ")
if playGame.upper()=="Y":
    msg="Number of players 0 or 1"
    displayMessage(msg)
    numberOfPlayers=int(raw_input(" "))
    if numberOfPlayers==0:
        player="Professor Flakner"
    else:
        player=user
    msg="How about Global Thermonuclear War?......"
    displayMessage(msg)
    sleep(2.0)
    msg="My apologies.\nThat game has been removed from my system. Lets play BattleShip\n\n"    
    displayMessage(msg)
    countryList=['China','Russia','SouthKorea','India','France','Mexico','Taiwan','Turkey','NorthKorea']
    if numberOfPlayers==1:
        msg="Which country would you like to play?\n"
        displayMessage(msg)
        for country in countryList:
            msg="%s \n"%country
            displayMessage(msg)
        enemy=raw_input(": ")
        msg="Very well.\n"
    msg="Please be patient as battle tatics and anaylsis are loaded\n"
    displayMessage(msg)
    for i in range(21): 
        sys.stdout.write('\r')
        sys.stdout.write("[%-20s] %d%%" % ('='*i, 5*i))
        sys.stdout.flush()
        sleep(0.25) 
    print "\n\n"
else:
    msg="A Strange Game.\nThe only winning move is not to play..\nHow about a nice game of chess.."
    displayMessage(msg)
    sys.exit()


gridSelection=raw_input("Would you like to define the size of of the grid ('Y' or 'N')? " )
if gridSelection.upper()=="Y":
    inputValuesValid="False"
    while inputValuesValid=="False":
        gridSize=int(raw_input("Input size of X and Y axis (Min:6  Max:26)? " ))
        if gridSize <6:
            print "Biggest ship is 6 units.. Will not fit on grid." 
        if gridSize >26:
            print "Nah dude..Max x and y xis size is 26  " 
        if gridSize >6  or gridSize <= 26: inputValuesValid="True";xGrid=gridSize;yGrid=gridSize


else:
    xGrid=10
    yGrid=10
myGridClass=grid('USA',xGrid,yGrid)
if numberOfPlayers==0:
    enemyGridClass=grid(random.choice(countryList),xGrid,yGrid)
else:
    enemyGridClass=grid(enemy,xGrid,yGrid)

turnList=determineMaxMoves(xGrid,yGrid,player)

myFleetClass=fleet()
enemyFleetClass=fleet()

#Set up grid values
enemyGridValues=enemyGridClass.gridValues
myGridValues=myGridClass.gridValues

#Sort our ships by size. 
sortedShipList=sorted(myFleetClass.shipFleetDict.iteritems(), key=operator.itemgetter(1),reverse=True)

#populate Computer/enemy grid 
setupNavy('random',enemyGridClass,sortedShipList)
enemyGridClass.populateGrid()

#setup the layout of our ships


#print "\n    %s has declared war!!\n\n" %enemyGridClass.gridName
if numberOfPlayers==1:
    choiceForSetup=raw_input("Would you like to manually place your ships ('Y' or 'N')?" )
else:
    choiceForSetup="N"

if choiceForSetup.upper()=='Y':
    #display empty grid
    myGridClass.populateGrid()
    myGridClass.displayGrid()
    setupNavy('manual',myGridClass,sortedShipList)
    myGridClass.populateGrid()
else: 
    setup='Y'
    while setup=="Y":
        setupNavy('random',myGridClass,sortedShipList)
        myGridClass.populateGrid()
        myGridClass.displayGrid()
        if numberOfPlayers==1:
            con=raw_input("Are you satisfied with your location of your ships ('Y' or 'N')? ")
        else:
            con="Y"
        if con.upper()=="Y":
            setup="N"
        else:
            myGridClass.gridValuesUsed=[]
            myGridValues=myGridClass.resetGridValues()

for whosTurn in turnList:
    print "\n\n%s turn"%whosTurn

    if whosTurn!="Joshua":
        if int(numberOfPlayers) ==1:
            whosTurn='player'
        attackShip(whosTurn,myGridClass,enemyGridClass,enemyFleetClass)
        myGridClass.attackCounter+=1
    else:
        attackShip(whosTurn,enemyGridClass,myGridClass,myFleetClass)
        enemyGridClass.attackCounter+=1
    print "\n    MY BATTLEFIELD"
    myGridClass.populateGrid()
    myGridClass.displayGrid()

    print "\n    MY ATTACKS"   
    myGridClass.populateEnemyGrid()
    myGridClass.displayEnemyGrid()

Fleet.py

class fleet:
    def __init__(self):
        #List of current ships of the United States Navy
        #Ship name         |           Size
        #--------------------------------------
        #airCraftCarrier               6   
        #battleShip                    5   
        #submarine                     4   
        #cruiser                       3   
        #destroyer                     2   

        self.shipFleetDict={'airCraftCarrier':6,
                            'battleship':5,
                            'submarine':4,
                            'cruiser':3,
                            'destroyer':2}

        self.shipStatusDict={'airCraftCarrier':'active',
                             'battleship':'active',
                             'submarine':'active',
                             'cruiser':'active',
                             'destroyer':'active'} 


        self.numberSunkShips=0

grid.py

import sys

class grid:
    def __init__(self,name,xSize,ySize):
        self.gridName =name 
        self.attackCounter=0
        self.hitList=[]
        self.missedList=[]
        self.gridValuesUsed=[]
        self.attackList=[]
        self.displayGridDict={}
        self.displayEnemyGridDict={}
        self.shipLocationDict={}
        self.xGridSize=xSize
        self.yGridSize=ySize
        self.gridValues=[ [ '[ ]' for i in range(self.yGridSize) ] for j in range(self.xGridSize) ]    
        self.gridValuesAttacked=[ [ '[ ]' for i in range(self.yGridSize) ] for j in range(self.xGridSize) ]    
        self.validPoints=self.defineValidPoints()
        self.alphList=map(chr, range(65, 91)) #create a list A-Z
        self.alphDict=self.generateDict()
        self.searchList=self.defineSearchList()



    def defineSearchList(self):
        searchList=[];start=0
        z=0 
        row=1
        for item in self.validPoints:
            if row%2==1 and z%2==0:
                searchList.append(item)
            if row%2==0 and (z-self.xGridSize)%2==1:
                searchList.append(item)
            if z%((self.xGridSize*row)-1)==0 and z>0:
                row+=1
            z+=1
        return searchList


    def defineValidPoints(self):
        validPoints=[]
        x=0
        while x < self.xGridSize: 
            y=0 
            while y < self.yGridSize:
                validPoints.append("%s,%s"%(x,y))
                y+=1
            x+=1
        return validPoints

    def generateDict(self):
        alphDict={}
        i=0
        for i in range(0, len(self.alphList)):
            alphDict[(ord(self.alphList[i])%32)-1] = self.alphList[i]
        return alphDict

    def resetGridValues(self):
        self.gridValues=[ [ '[ ]' for i in range(self.yGridSize) ] for j in range(self.xGridSize) ]
        return self.gridValues 

    def checkDataPointValue(self,dataPoint):
        xValue=dataPoint[:1] 
        yValue=int(dataPoint[1:]) 
        xValue=int((ord(xValue)%32)-1)
    coords="%s,%s"%(xValue,yValue)
        if coords in self.gridValuesUsed:
            return "T"
        else:
            return "E"

    def determineEndPoint(self,start,size,placement):
        x=start[:1]
        y=start[1:]
        if placement.upper()=='V':
            yEnd=(int(y)+size)-1
            if yEnd > self.yGridSize-1: return "F" 
            endPoint="%s%s"%(x,str(yEnd))
        else:
            xValueNumber=(ord(x)%32)-1
            xEnd=xValueNumber+size-1
            if xEnd > self.xGridSize-1: return "F" 
            endPoint="%s%s"%(self.alphList[xEnd],y)
        return endPoint

    def determineFullLocation(self,start,end):
        xValueStart=start[:1]
        yValueStart=int(start[1:])
        xValueEnd=end[:1]
        yValueEnd=int(end[1:])
        shipCoordList=[]
        if xValueStart==xValueEnd: #placing vertical
            xValueNumber=(ord(xValueStart)%32)-1
            i=yValueStart 
            while i <= yValueEnd:
                #shipCoordList.append('%s,%s'%(i,xValueNumber))
                shipCoordList.append('%s,%s'%(xValueNumber,i))
                i+=1
        else:
            xValueStart=(ord(xValueStart)%32)-1
            xValueEnd=(ord(xValueEnd)%32)-1
            i=xValueStart 
            while i <= xValueEnd:
                #shipCoordList.append('%s,%s'%(yValueStart,i))
                shipCoordList.append('%s,%s'%(i,yValueStart))
                i+=1

        return shipCoordList

    def shipPlacement(self,start,end,shipCoordList):
        xValueStart=start[:1]
        xValueEnd=end[:1]
        #block='█'
        block='■'
        if xValueStart==xValueEnd: #placing vertical
            for coord in shipCoordList:
                coordList=coord.split(',')
                #yValue=int((ord(coordList[0])%32)-1)
                xValue=int(coordList[0])
                yValue=int(coordList[1])
                displayVal="[%s]"%block
                #displayVal="[*]"
                self.gridValues[xValue][yValue]=displayVal
        else: #placing horizontal
            i=1
            size=len(shipCoordList)
            for coord in shipCoordList:
                coordList=coord.split(',')
                xValue=int(coordList[0])
                yValue=int(coordList[1])
                if i ==1:
                    #displayVal="[* "
                    displayVal="[%s "%block
                elif i==size:
            #displayVal=" *]"
            displayVal=" %s]"%block
                else:
                    #displayVal=" * "
                    displayVal=" %s "%block
                self.gridValues[xValue][yValue]=displayVal
                i+=1
        return 



    def populateGrid(self):
        y=0
        #gridDict={}
        numElements=len(self.gridValues)
        while y < self.yGridSize:
            values=[]
            x=0 
            while x < self.xGridSize:
                values.append(self.gridValues[x][y]) 
                x+=1
            #YGRID
            if numElements>9:
                yDisplay="%02d" % (y,)
                self.displayGridDict[yDisplay]=values
            else:
                self.displayGridDict[y]=values
            values=[]
            y+=1
        return


    def displayGrid(self):
        row=0
        header=""
        numElements= len(self.displayGridDict)
        x=0
        while x<numElements:
            header+="[%s]"%self.alphList[x]
            x+=1
        numElements=len(self.displayGridDict)
        for key in sorted(self.displayGridDict.iterkeys()):
            value=self.displayGridDict[key]
            if row==0:
                if numElements>9:
                    displayStr="  %s\n"%(header)
                else:
                    displayStr=" %s\n"%(header)
                sys.stdout.write(displayStr)
                displayStr=""
            displayStr+="%s"%key

            for cell in value:
                displayStr+="%s"%cell
            displayStr+="\n"
            sys.stdout.write(displayStr)
            displayStr=""
            row+=1


    def populateEnemyGrid(self):
        y=0
        #gridDict={}
        numElements=len(self.gridValuesAttacked)
        while y < self.yGridSize:
            values=[]
            x=0 
            while x < self.xGridSize:
                values.append(self.gridValuesAttacked[x][y]) 
                x+=1
            if numElements>9:
                yDisplay="%02d" % (y,)
                self.displayEnemyGridDict[yDisplay]=values
            else:
                self.displayEnemyGridDict[y]=values
            values=[]
            y+=1
        return


    def displayEnemyGrid(self):
        row=0
        header=""
        numElements= len(self.displayEnemyGridDict)
        x=0
        while x<numElements:
            header+="[%s]"%self.alphList[x]
            x+=1
        numElements=len(self.displayEnemyGridDict)
        for key in sorted(self.displayEnemyGridDict.iterkeys()):
            value=self.displayEnemyGridDict[key]
            if row==0:
                if numElements>9:
                    displayStr="  %s\n"%(header)
                else:
                    displayStr=" %s\n"%(header)
                sys.stdout.write(displayStr)
                displayStr=""
            displayStr+="%s"%key

            for cell in value:
                displayStr+="%s"%cell
            displayStr+="\n"
            sys.stdout.write(displayStr)
            displayStr=""
            row+=1
\$\endgroup\$
1
1
\$\begingroup\$
  • Get rid of magic numbers and magic strings (see also second point).

  • Use relevant types (and not just strings).

If you want to have a variable with two different status (yes/no, true/false, active/sunk, etc), it would probably make sense to use booleans.

If you want to have a variable with a limited number of different values, you might want to use something better than string (you could use or emulate enums).

  • Organise your code in a better way.

You've started to create classes which is probably a good idea. However, I am not quite sure that it makes sense to make things that complicated. Also, the dependency between the different parts of the code suggest that the definition is not as good as it could be.

I might be missing something but things could be pretty simple :

A game is a list of players and the record of the player who is supposed to play.

A player is just a name, a type of user (bot or player) and a board

A board is just a table of cells.

Each cell contains two pieces of information : what it contains (airCraftCarrier, battleship, submarine, cruiser, destroyer or water) and whether is has been bombed.

As most of these concepts are basically just container with no or little logic, it might or might not make sense to use classes for them. This is up to you.

  • Don't repeat yourself.

Whenever you are writing the same piece of code twice, you are punishing your future self. If one of them needs to be updated, the other will need to be too which is going to be boring in the best case, forgotten and lead to weird bugs in the worst case.

  • Let's do things in a pythonic way

You've written :

i=0;turnList=[]
maxTurns=(xGrid*yGrid)*2
while i < maxTurns:
    if i%2==0:
        #turnList.append('player')
        turnList.append(player)
    else:
        turnList.append('Joshua')
    i+=1
return turnList

which becomes, after using range (or xrange), removing useless parenthesis useless comments and useless variables and using the ternary operator (which is a good way to remove duplicated code) :

turnList=[]
for i in range(xGrid*yGrid*2):
    turnList.append('Joshua' if i%2 else player) 
return turnList

which now looks like a good candidate for list comprehension :

return [('Joshua' if i%2 else player) for i in range(xGrid*yGrid*2)]

The same kind of idea applies to :

    validPoints=[]
    x=0
    while x < self.xGridSize:
        y=0
        while y < self.yGridSize:
            validPoints.append("%s,%s"%(x,y))
            y+=1
        x+=1
    return validPoints

becomes :

    validPoints=[]
    for x in range(self.xGridSize): 
        for y in range(self.yGridSize):
            validPoints.append("%s,%s"%(x,y))
    return validPoints

and could then be transformed with list comprehension. However, I'd like to point out that this method : 1) probably shouldn't be doing the string conversion itself 2) doesn't seem that useful.

I don't have more time to continue but I guess that's already a good amount of comments to start with.

\$\endgroup\$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.