Example #1
0
 def checkRow(self, row):
     beginn = row[R_Beginn]
     ende = row[R_Ende]
     dauer = utils.tsub(ende, beginn)
     if dauer[0] == '-':
         return "Ende vor Beginn"
     if dauer == "00:00":
         return "Beginn gleich Ende"
     if int(dauer[0:2]) >= 12:
         return "Beginn bis Ende mehr als 12 Stunden"
     return None
Example #2
0
    def makeRow(self, er, dsum, nsum, uesum, sollstunden, exrownr):
        er[Arbeitsstunden] = utils.hhmm2td(dsum)
        ueberstunden = "00:00"
        if dsum == "00:00" and nsum == "00:00" and uesum == "00:00":
            # nicht möglich
            sollstunden = "00:00"
        elif dsum == "00:00" and nsum == "00:00" and uesum != "00:00":
            ueberstunden = "-" + sollstunden
        elif dsum == "00:00" and nsum != "00:00" and uesum == "00:00":
            sollstunden = "00:00"
        elif dsum == "00:00" and nsum != "00:00" and uesum != "00:00":
            ueberstunden = "-" + uesum
            sollstunden = utils.tsub(sollstunden, nsum)
        elif dsum != "00:00" and nsum == "00:00" and uesum == "00:00":
            ueberstunden = utils.tsub(dsum, sollstunden)
        elif dsum != "00:00" and nsum == "00:00" and uesum != "00:00":
            ueberstunden = utils.tsub(dsum, sollstunden)
        elif dsum != "00:00" and nsum != "00:00" and uesum == "00:00":
            sollstunden = utils.tsub(sollstunden, nsum)
        elif dsum != "00:00" and nsum != "00:00" and uesum != "00:00":
            sollstunden = utils.tsub(sollstunden, nsum)
            ueberstunden = utils.tsub(dsum, sollstunden)

        er[Ueberstunden] = utils.hhmm2td(ueberstunden)
        er[Sollstunden] = utils.hhmm2td(sollstunden)
        self.kumArb = utils.tadd(self.kumArb, dsum)
        self.kumSoll = utils.tadd(self.kumSoll, sollstunden)
        self.kumUeber = utils.tadd(self.kumUeber, ueberstunden)
        er[Kumuliert] = utils.hhmm2td(self.kumUeber)
        er[KumFormel] = "=S" + str(exrownr + 1) + "+U" + str(exrownr)
Example #3
0
def refine(board, pos, fpositions, chain = []):
    """ 
    Returns the refined future positions for given stone,
    by applying game constraints.
    Also appends the move type to each possible position.
    
    *The f in fpos, fpositions stands for "future".
    """
    if chain:
        chain = [v[0] for v in chain]
    refined = []
    for fpos in fpositions:
        x, y = pos # old position
        d = utils.tsub(fpos, pos) #direction
        
        # check for validity when chaining:
        #    - have we already visited the future position?
        #    - is the direction the same as before?
        # for more info on this look up the fanorona rules.
        if chain:
            if fpos in chain or d == utils.tsub(pos, chain[-1]):
                continue
            
        # approach
        ax, ay = utils.tadd(fpos, d)
        if board.valid((ax, ay)) and not board.empty((ax, ay)) and board[ax][ay] != board[x][y]:
            refined.append((fpos, A))
        
        # withdraw
        wx, wy = utils.tsub(pos, d)
        if board.valid((wx, wy)) and not board.empty((wx, wy)) and board[wx][wy] != board[x][y]:
            refined.append((fpos, W))
    
    # if no capturing moves found and not chaining, return paikas.
    if not refined and not chain:
        for fpos in fpositions:
            refined.append((fpos, P))
        
    return refined
Example #4
0
def captured(board, pos, move):
    """ Returns a list of captured stones according to the capture type."""
    fpos, captype = move
    if captype == P:
        return []
    
    captured = []
    ox, oy = capx, capy = pos
    color = board[ox][oy]
    d = utils.tsub(fpos, pos)
    
    if captype == A:
        cpos = capx, capy = utils.tadd(fpos, d)
    else:
        cpos = capx, capy = utils.tsub(pos, d)
        
    while board.valid((capx, capy)) and not board.empty((capx, capy)) and board[capx][capy] != color:
        captured.append(cpos)
        if captype == A:
            cpos = capx, capy = utils.tadd(cpos, d)
        else:
            cpos = capx, capy = utils.tsub(cpos, d)
    return captured
Example #5
0
 def update(self):
     """
     Updates ongoing move (if it exists).
     """
     if self.m:
         sx, sy, dx, dy = itertools.chain.from_iterable(self.m)
         start = self[sx][sy]
         dest = self[dx][dy]
         d = utils.tsub((dx,dy),(sx,sy)) # calculate direction
         if start.rect.topleft == dest.rect.topleft:
             # reached destination
             self[sx][sy].rect = self.original
             self[dx][dy].image = self[sx][sy].image
             self[sx][sy].image = NULL_IMG
             self.m = []
             game.moving = False
             if game.current == game.player:
                 game.move()
         else:
             # keep moving
             start.rect.topleft = utils.tadd(start.rect.topleft, utils.tflip(d))