Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Insane Math Questions. Those With Weak Hearts Beware.
#11
this might get you started on doing the first problem:

Code:
class bitboard:
    def __init__(self):
        self.bitboard = [[2,2,1,5,2,6,8,0,3,2,9,4,8,5,1,4,6,3,9,1],
                         [6,0,3,9,3,6,3,5,9,5,5,7,7,9,8,2,1,8,7,5],
                         [8,6,8,5,9,4,8,1,1,1,7,4,4,3,1,0,4,3,4,3],
                         [6,3,1,1,0,4,1,8,4,2,6,7,0,6,0,5,4,3,9,0],
                         [9,5,9,4,0,1,9,9,8,5,9,8,2,2,0,2,6,3,5,3],
                         [0,9,3,8,8,5,8,3,8,7,7,9,6,3,2,8,9,7,3,4],
                         [1,3,3,7,2,6,6,0,6,2,8,0,3,4,4,5,3,9,0,8]]
        self.width = len(self.bitboard[0])
        self.height = len(self.bitboard)

        self.ShapeAssignValue = 0x80000000
        self.ShapeDescriptions = []

    def RegisterShape(self, Description):
        self.ShapeDescriptions.append(Description)
        self.ShapeAssignValue >>= 1
        if self.ShapeAssignValue < 16:
            raise Exception("Cannot assign any new shapes")
        return self.ShapeAssignValue

    def GetShapeAtOffset(self, xcoord, ycoord):
        if self.ShapeAssignValue == 0x80000000:
            return "NO SHAPES ASSIGNED"
        else:
            bitboardvalue = self.bitboard[xcoord][ycoord]
            shapeassignvalue = 0x80000000
            iterator = 0
            while shapeassignvalue > 16:
                if shapeassignvalue & bitboardvalue == 1:
                    shapeassignvalue >>= 1
                    return self.ShapeDescriptions[iterator]
                else:
                    iterator += 1
                

    def GetShapeValues(self, xcoord, ycoord, xybitfield, value):
        return sum([self.bitboard[xcoord + xbit][ycoord + ybit] for xbit, ybit in xybitfield]) * (value + 1)

class shape:
    def __init__(self, description, height, width, offsets, value):
        self.description = description
        self.height = height
        self.width = width
        self.offsets = offsets
        self.value = value
Reply


Messages In This Thread
Insane Math Questions. Those With Weak Hearts Beware. - by Fiel - 2010-04-16, 04:51 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)