Transaction #236

Hash 4d883b59c09705ecf62b7565aee54485c1dbfe80f756a1998473e584332f445f
Status Success
Timestamp 455 days ago - 2/1/2023, 5:56:11 AM UTC+0
Block 236
Stamps Used 212
Burned Fee 0.01254438 TAU
From a02dde674a13d6fb71ac08f79b5ae1e23e4c43af4d8fbd05c7b2db6f167d7adc 
Contract Name submission
Function Name submit_contract

Additional Info
Nonce 27
Processor e79133b02cd2a84e2ce5d24b2f44433f61f0db7e10acedfc241e94dff06f710a
Signature 8bb27133a244e2f9683d53b22907d7decf5875b3535de565b503f249ab7b0af2385e9edcf8a750aa39980fbb84f4f3ca0d9344520a232177719d3505b8bbfb0b
Stamps Supplied 300
Stamps per TAU 169

Kwargs

code ### # This is a simple smart contract # All Lamden smart contracts are programmed in Python # For complete contracting documentation please visit https://contracting.lamden.io/ ### # import random random.seed() games = Hash(default_value=False) metadata = Hash() @construct def seed(): metadata['operator'] = ctx.caller @export def change_metadata(key: str, value: Any): assert ctx.caller == metadata['operator'], 'Only operator can set metadata!' metadata[key] = value @export def create_game(): sender = ctx.caller assert games[sender] == False, 'Game already in progress' first = random.randint(0, 99) # 0 = not set, 1 = O, 2 = X if(first <50): first = 1 # Player goes first else: first = 2 # Computer goes first games[sender] = {'first': first, 'state': [0, 0, 0, 0, 0, 0, 0, 0, 0], 'turn': 0} return games[sender] @export def end_game(): games[ctx.caller] = False @export def player_selection(i: int): sender = ctx.caller game = games[sender] assert not(game == False), 'No game already in progress' game['state'][i] = 1 assert not(game['state'][i] == 0), f'square {i} is already closed' game['turn'] = game['turn'] + 1 win = False if(game['turn'] >= 9): games[sender] = False return "{'winner': 0, 'state': " + f"{game['state']}" + "}" if(game['turn'] >= 5 and checkWin(game['state'], 1)): games[sender] = False return "{'winner': 1, 'state': " + f"{game['state']}" +"}" else: computerSelects = random.randint(0, 8) while(game['state'][computerSelects] != 0): computerSelects = random.randint(0, 8) game['state'][computerSelects] = 2 game['turn'] = game['turn'] + 1 if(game['turn'] >= 9): games[sender] = False return "{'winner': 0, 'state': " + f"{game['state']}" + "}" if(game['turn'] >= 5 and checkWin(game['state'], 2)): games[sender] = False return "{'winner': 2, 'state': " + f"{game['state']}" + "}" games[sender] = game return f'{game}' def checkWin(state, x: int): if(state[0] == x): # top left if(state[1] == x and state[1] == x): #top row return True if(state[3] == x and state[6] == x): #left column return x if(state[4] == x and state[8] == x): # diagnal top left to bottom right return True if(state[1] == x): # top middle if(state[4] == x and state[7] == x): # middle column return True if(state[2] == x): # top right if(state[5] == x and state[8] == x): #right column return True if(state[4] == x and state[6] == x): # diagnal top right to bottom left return True if(state[3] == x): # top middle if(state[4] == x and state[5] == x): # middle row return True if(state[6] == x): # top middle if(state[7] == x and state[8] == x): # bottom row return True return False # print(checkWin([1, 2, 0, 2, 1, 0, 0, 0, 1], 1))
name con_tictactoe_v19

State Changes

Contract con_tictactoe_v19
Variable metadata
Key operator
New Value a02dde674a13d6fb71ac08f79b5ae1e23e4c43af4d8fbd05c7b2db6f167d7adc
 
Contract con_tictactoe_v19
Variable __code__
New Value random.seed() __games = Hash(default_value=False, contract='con_tictactoe_v19', name='games') __metadata = Hash(contract='con_tictactoe_v19', name='metadata') def ____(): __metadata['operator'] = ctx.caller @__export('con_tictactoe_v19') def change_metadata(key: str, value: Any): assert ctx.caller == __metadata['operator' ], 'Only operator can set metadata!' __metadata[key] = value @__export('con_tictactoe_v19') def create_game(): sender = ctx.caller assert __games[sender] == False, 'Game already in progress' first = random.randint(0, 99) if first < 50: first = 1 __games[sender] = {'first': first, 'state': [0, 0, 0, 0, 0, 0, 0, 0, 0], 'turn': 0} return __games[sender] @__export('con_tictactoe_v19') def end_game(): __games[ctx.caller] = False @__export('con_tictactoe_v19') def player_selection(i: int): sender = ctx.caller game = __games[sender] assert not game == False, 'No game already in progress' game['state'][i] = 1 assert not game['state'][i] == 0, f'square {i} is already closed' game['turn'] = game['turn'] + 1 win = False if game['turn'] >= 9: __games[sender] = False return "{'winner': 0, 'state': " + f"{game['state']}" + '}' if game['turn'] >= 5 and __checkWin(game['state'], 1): __games[sender] = False return "{'winner': 1, 'state': " + f"{game['state']}" + '}' else: computerSelects = random.randint(0, 8) while game['state'][computerSelects] != 0: computerSelects = random.randint(0, 8) game['state'][computerSelects] = 2 game['turn'] = game['turn'] + 1 if game['turn'] >= 9: __games[sender] = False return "{'winner': 0, 'state': " + f"{game['state']}" + '}' if game['turn'] >= 5 and __checkWin(game['state'], 2): __games[sender] = False return "{'winner': 2, 'state': " + f"{game['state']}" + '}' __games[sender] = game return f'{game}' def __checkWin(state, x: int): if state[0] == x: if state[1] == x and state[1] == x: return True if state[3] == x and state[6] == x: return x if state[4] == x and state[8] == x: return True if state[1] == x: if state[4] == x and state[7] == x: return True if state[2] == x: if state[5] == x and state[8] == x: return True if state[4] == x and state[6] == x: return True if state[3] == x: if state[4] == x and state[5] == x: return True if state[6] == x: if state[7] == x and state[8] == x: return True return False
 
Contract con_tictactoe_v19
Variable __compiled__
New Value e30000000000000000000000000500000040000000738a00000065006a0183000100650264006401640264038d035a0365026401640464058d025a046406640784005a056506640183016507650864089c026409640a840483015a09650664018301640b640c840083015a0a650664018301640d640e840083015a0b650664018301650c640f9c0164106411840483015a0d650c64129c016413641484045a0e64155300291646da11636f6e5f746963746163746f655f763139da0567616d65732903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da086d65746164617461290272040000007205000000630000000000000000000000000300000043000000730e00000074006a01740264013c006400530029024eda086f70657261746f722903da03637478da0663616c6c6572da0a5f5f6d65746164617461a900720b000000720b000000da00da045f5f5f5f0600000073020000000001720d0000002902da036b6579da0576616c7565630200000000000000020000000300000043000000732200000074006a017402640119006b02731674036402830182017c0174027c003c006400530029034e72070000007a1f4f6e6c79206f70657261746f722063616e20736574206d6574616461746121290472080000007209000000720a000000da0e417373657274696f6e4572726f722902720e000000720f000000720b000000720b000000720c000000da0f6368616e67655f6d657461646174610a00000073060000000002100106017211000000630000000000000000020000000a00000043000000735c00000074006a017d0074027c00190064016b02731a740364028301820174046a056403640483027d017c0164056b00723264067d017c016403640364036403640364036403640364036709640364079c0374027c003c0074027c001900530029084e467a1847616d6520616c726561647920696e2070726f6772657373e900000000e963000000e932000000e9010000002903da056669727374da057374617465da047475726e290672080000007209000000da075f5f67616d65737210000000da0672616e646f6dda0772616e64696e742902da0673656e6465727216000000720b000000720b000000720c000000da0b6372656174655f67616d651100000073100000000002060114010c010801040116010c01721d000000630000000000000000000000000300000043000000730e0000006401740074016a023c006400530029024e462903721900000072080000007209000000720b000000720b000000720b000000720c000000da08656e645f67616d651d00000073020000000002721e0000002901da0169630100000000000000050000000400000043000000737401000074006a017d0174027c0119007d027c0264016b020c007320740364028301820164037c02640419007c003c007c02640419007c00190064056b020c00734e740364067c009b0064079d03830182017c0264081900640317007c0264083c0064017d037c026408190064096b057288640174027c013c00640a7c02640419009b001700640b170053007c0264081900640c6b0572bc74047c02640419006403830272bc640174027c013c00640d7c02640419009b001700640b1700530074056a066405640e83027d0478207c02640419007c04190064056b0372e874056a066405640e83027d0471ca5700640f7c02640419007c043c007c0264081900640317007c0264083c007c026408190064096b059001722e640174027c013c00640a7c02640419009b001700640b170053007c0264081900640c6b059001726674047c0264041900640f830290017266640174027c013c0064107c02640419009b001700640b170053007c0274027c013c007c029b00530029114e467a1b4e6f2067616d6520616c726561647920696e2070726f67726573737215000000721700000072120000007a07737175617265207a1220697320616c726561647920636c6f7365647218000000e9090000007a177b2777696e6e6572273a20302c20277374617465273a20da017de9050000007a177b2777696e6e6572273a20312c20277374617465273a20e908000000e9020000007a177b2777696e6e6572273a20322c20277374617465273a2029077208000000720900000072190000007210000000da0a5f5f636865636b57696e721a000000721b0000002905721f000000721c000000da0467616d65da0377696eda0f636f6d707574657253656c65637473720b000000720b000000720c000000da10706c617965725f73656c656374696f6e22000000733400000000020601080112010c012201100104010c01080112011a01080112020c01120110010c0110010e01080112011e0108011201080172290000002901da017863020000000000000002000000020000004300000073260100007c00640119007c016b0272607c00640219007c016b0272287c00640219007c016b027228640353007c00640419007c016b0272447c00640519007c016b0272447c0153007c00640619007c016b0272607c00640719007c016b027260640353007c00640219007c016b0272887c00640619007c016b0272887c00640819007c016b027288640353007c00640919007c016b0272cc7c00640a19007c016b0272b07c00640719007c016b0272b0640353007c00640619007c016b0272cc7c00640519007c016b0272cc640353007c00640419007c016b0272f47c00640619007c016b0272f47c00640a19007c016b0272f4640353007c00640519007c016b02900172227c00640819007c016b02900172227c00640719007c016b029001722264035300640b5300290c4e7212000000721500000054e903000000e906000000e9040000007223000000e9070000007224000000722200000046720b00000029027217000000722a000000720b000000720b000000720c000000722500000041000000732c00000000010c011801040118010401180104010c01180104010c0118010401180104010c01180104010e011c01040172250000004e290f721a000000da0473656564da04486173687219000000720a000000720d000000da085f5f6578706f7274da03737472da03416e797211000000721d000000721e000000da03696e7472290000007225000000720b000000720b000000720b000000720c000000da083c6d6f64756c653e01000000731400000008010e010c03080406011206100c10050601101e
 
Contract con_tictactoe_v19
Variable __owner__
New Value null
 
Contract con_tictactoe_v19
Variable __submitted__
New Value 2023,2,1,5,56,12,0
 
Contract con_tictactoe_v19
Variable __developer__
New Value a02dde674a13d6fb71ac08f79b5ae1e23e4c43af4d8fbd05c7b2db6f167d7adc
 
Contract currency
Variable balances
Key a02dde674a13d6fb71ac08f79b5ae1e23e4c43af4d8fbd05c7b2db6f167d7adc
New Value 1406.16307638153845617