This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.7.0 <0.9.0; | |
contract Storage { | |
uint256 number; | |
function store(uint256 num) public { | |
number = num; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<void> getBalance() async { | |
setState(() => {loading = true}); | |
List<dynamic> result = await query('balance', []); | |
balance = int.parse(result[0].toString()); | |
setState(() => {loading = false}); | |
} | |
Future<void> deposit(int amount) async { | |
BigInt parsedAmount = BigInt.from(amount); | |
await transaction("deposit", [parsedAmount]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<DeployedContract> getContract() async { | |
// abi.json is the contract metadata, you can download it from the remix IDE | |
String abi = await rootBundle.loadString("assets/abi.json"); | |
String contractAddress = "my_contract_address"; // e.g. 0xd66C81d9b781152e2D9be07Ccdf2303A77B7163c | |
String contractName = "my_contract_name"; // you must set your own contract name here | |
DeployedContract contract = DeployedContract( | |
ContractAbi.fromJson(abi, contractName), | |
EthereumAddress.fromHex(contractAddress), | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<List<dynamic>> query(String functionName, List<dynamic> args) async { | |
DeployedContract contract = await getContract(); | |
ContractFunction function = contract.function(functionName); | |
List<dynamic> result = await ethereumClient.call( | |
contract: contract, function: function, params: args); | |
return result; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity 0.8.7; | |
contract Fluthereum { | |
int public balance; | |
constructor() { | |
balance = 0; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mk.loadModels = async function () { | |
this.subzeroModel = await tf.loadLayersModel('https://raw.githubusercontent.com/MCarlomagno/RLMortalKombat/master/models/subzeroModel/model.json'); | |
this.kanoModel = await tf.loadLayersModel('https://raw.githubusercontent.com/MCarlomagno/RLMortalKombat/master/models/kanoModel/model.json'); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var saveTargetModels = async function() { | |
// DeepMortalKombatTraining is the mk game repository | |
await subzeroTargetModel.save('file:///home/marcos/Repositories/DeepMortalKombatTraining/models/subzeroModel'); | |
await kanoTargetModel.save('file:///home/marcos/Repositories/DeepMortalKombatTraining/models/kanoModel'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mk.startAIFight = async function () { | |
var sleep = (milliseconds) => { | |
return new Promise(resolve => setTimeout(resolve, milliseconds)) | |
} | |
while (true) { | |
var state = mk.getState(); | |
subzeroAction = mk.predictSubzeroAction(state); | |
kanoAction = mk.predictKanoAction(state); | |
mk.executeSubzeroAction(subzeroAction); | |
mk.executeKanoAction(kanoAction); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var underscore = require('underscore'); | |
var replay = async function (batchSize, index) { | |
var minibatch = []; | |
if (index === subzeroIndex) { | |
minibatch = underscore.sample(subzeroMemory, batchSize); | |
} else { | |
minibatch = underscore.sample(kanoMemory, batchSize); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var memorize = function (state, action, reward, nextState, done, memory) { | |
memory.push({state, action, reward, nextState, done}); | |
} |