Esempio n. 1
0
def easy1(challenge, student, code, completed):
    a = Assembler()
    rom, errors = a.assemble( """%s
                              .org $C000
                              .define PLAYER_X=$200
                              .define PLAYER_Y=$201
                              %s
                              forever: jmp forever
                              .org $fffa
                              .dw $C000
                              .dw $C000
                              .dw $C000
                              """%(memmap, code) )
    if errors: return None
    
    counts = []
    for test in [[0],[1],[2],[3],[4],[5],[6],[7],[4,5],[4,6],[4,7],[5,7],[4,5,6,7]]:
        e = Emulator( rom[0x10:0x4010], rom[0x4010:] )
        x = 74
        y = 32
        e.write(x,0x200)
        e.write(y,0x201)
        for t in test:
            e.controller(1, t)
        if 4 in test: y-=1
        if 5 in test: y+=1
        if 6 in test: x-=1
        if 7 in test: x+=1
        counts.append( run( e, 0x100 ) )
        if e.read(0x200) != x or e.read(0x201) != y:
            return None
    return rom_size(rom), sum(counts)/len(counts)
Esempio n. 2
0
def medium1(challenge, student, code, completed):
    a = Assembler()
    rom, errors = a.assemble( """%s
                              .org $C000
                              %s
                              forever: jmp forever
                              .org $fffa
                              .dw $C000
                              .dw $C000
                              .dw $C000
                              """%(memmap, code) )
    if errors: return None
    
    # Testing this one is easy. We simply create lists and then see if the
    # student's sort matches Python's. We will randomly create 5 lists to
    # average out "best cases". Granted, this means that it's possible for
    # a student to beat the "record" by just running the code multiple times,
    # but more efficient sorts should always win out.
    counts = []
    for test in range(5):
        e = Emulator( rom[0x10:0x4010], rom[0x4010:] )
        l = []
        for i in range(64): l.append(random.randint(0,255))
        for i in range(64): e.write( l[i], 0x200+i )
        
        counts.append( run( e, 0x10000 ) )
        l.sort()
        
        for i in range(64):
            if e.read( 0x200+i) != l[i]: return None
    
    return rom_size(rom), sum(counts)/len(counts)
Esempio n. 3
0
def barcamp2(challenge, student, code, completed):
    a = Assembler()
    
    preamble = ".org $C000\n.define BALL_X=$200\n.define BALL_Y=$201\n.define BALL_DX=$202\n.define BALL_DY=$203\n"
    postamble = "\nforever:\n jmp forever\n.org $fffa\n.dw $C000\n.dw $C000\n.dw $C000"
    
    rom, errors = a.assemble( preamble+code + postamble )
    if errors: return None
    for test in [[54,32,1,1],[0,99,0xff,0xff],[55,0xff,0xff,1]]:
        e = Emulator( rom[0x10:0x4010], rom[0x4010:] )
        e.write( test[0], 0x200 )
        e.write( test[1], 0x201 )
        e.X = test[2]
        e.Y = test[3]
        for i in range(0x100):
            e.step()
            if e.last_op == 0x60: break
        if e.read(0x200) != (test[0]+test[2])&0xff or e.read(0x201) != (test[1]+test[3])&0xff:
            return None
    return rom_size(rom), 100
Esempio n. 4
0
def barcamp2(challenge, student, code, completed):
    a = Assembler()

    preamble = ".org $C000\n.define BALL_X=$200\n.define BALL_Y=$201\n.define BALL_DX=$202\n.define BALL_DY=$203\n"
    postamble = "\nforever:\n jmp forever\n.org $fffa\n.dw $C000\n.dw $C000\n.dw $C000"

    rom, errors = a.assemble(preamble + code + postamble)
    if errors: return None
    for test in [[54, 32, 1, 1], [0, 99, 0xff, 0xff], [55, 0xff, 0xff, 1]]:
        e = Emulator(rom[0x10:0x4010], rom[0x4010:])
        e.write(test[0], 0x200)
        e.write(test[1], 0x201)
        e.X = test[2]
        e.Y = test[3]
        for i in range(0x100):
            e.step()
            if e.last_op == 0x60: break
        if e.read(0x200) != (test[0] + test[2]) & 0xff or e.read(
                0x201) != (test[1] + test[3]) & 0xff:
            return None
    return rom_size(rom), 100
Esempio n. 5
0
def barcamp3(challenge, student, code, completed):
    a = Assembler()
    
    preamble = ".org $C000\n.define PADDLE_1Y=$204\n"
    postamble = "\nforever:\n jmp forever\n.org $fffa\n.dw $C000\n.dw $C000\n.dw $C000"
    
    rom, errors = a.assemble( preamble+code + postamble )
    if errors: None
    for test in [[0],[4],[5],[4,3]]:
        e = Emulator( rom[0x10:0x4010], rom[0x4010:] )
        for t in test: e.controller(1,t)
        for i in range(0x100):
            e.step()
            if e.last_op == 0x60: break
        if 4 in test and e.read(0x204) != 1: return None
        if 5 in test and e.read(0x204) != 0xff: return None
    return rom_size(rom), 100
Esempio n. 6
0
def barcamp3(challenge, student, code, completed):
    a = Assembler()

    preamble = ".org $C000\n.define PADDLE_1Y=$204\n"
    postamble = "\nforever:\n jmp forever\n.org $fffa\n.dw $C000\n.dw $C000\n.dw $C000"

    rom, errors = a.assemble(preamble + code + postamble)
    if errors: None
    for test in [[0], [4], [5], [4, 3]]:
        e = Emulator(rom[0x10:0x4010], rom[0x4010:])
        for t in test:
            e.controller(1, t)
        for i in range(0x100):
            e.step()
            if e.last_op == 0x60: break
        if 4 in test and e.read(0x204) != 1: return None
        if 5 in test and e.read(0x204) != 0xff: return None
    return rom_size(rom), 100
Esempio n. 7
0
def hard1(challenge, student, code, completed):
    a = Assembler()
    rom, errors = a.assemble( """%s
                              .org $C000
                              %s
                              forever: jmp forever
                              .org $fffa
                              .dw $C000
                              .dw $C000
                              .dw $C000
                              """%(memmap, code) )
    print errors
    if errors: return None
    

    
    # We do two basic tests. In the first, we simply start with a completely
    # filled grid. All cells should die.
    counts = []
    e = Emulator( rom[0x10:0x4010], rom[0x4010:] )
    for i in range(0x100):
        e.write( 1, 0x200+i )
    counts.append( run( e, 0x100000 ) )
    for i in range(0x100):
        if e.read( 0x200+i ) != 0: return None
    
    # This is the real test. Note that we will actually run the program two times
    # to ensure that there are no side effects.
    start = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
              0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
              1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1,
              0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
    stage1= [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
              0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
              1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1,
              0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 ]
    stage2= [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
              0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
              1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1,
              0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
    
    e = Emulator( rom[0x10:0x4010], rom[0x4010:] )
    for i in range(0x100):
        e.write( start[i], 0x200+i )
    counts.append( run( e, 0x100000 ) )
    for i in range(0x100):
        if e.read( 0x200+i ) != stage1[i]: return None
    e.PC = 0xC000
    counts.append( run( e, 0x100000 ) )
    for i in range(0x100):
        if e.read( 0x200+i ) != stage2[i]: return None
    
    print "OK"
    return rom_size(rom), sum(counts)/len(counts)