Skip to content

Velluscinum JaCaMo Chef and Glutton

Nilson Lazarin edited this page Sep 12, 2024 · 1 revision
Velluscinum for JaCaMo Wiki

To install JaCaMo-CLI on your computer, see the APT Package for JaCaMo CLI

Creating a JaCaMo Project

jacamo app create chefBankGlutton

Configuring Project

  • Edit the project file chefBankGlutton/chefBankGlutton.jcm as below:

     mas chefBankGlutton {
    
     agent bank
     agent chef   
     agent glutton
    
     uses package: velluscinum "com.github.chon-group:Velluscinum:+"
     }
    
  • Create the file chefBankGlutton/src/agt/bank.asl with the content below:

    Agent bank content file
     // Agent bank in project chefBankGlutton
     /* Initial beliefs and rules */
     chainServer("http://testchain.chon.group:9984/").
    
     /* Initial goals */
     !createCoin.
    
     /* Plans */ 
     +!createCoin
     :chainServer(Server) <-
     	.print("Creating digital wallet");
     	.velluscinum.buildWallet(myWallet);
     	.wait(myWallet(PrK,PuK));
    
     	.print("Creating and sharing a cryptocurrency");
     	.velluscinum.deployToken(Server,PrK,PuK,"name:ChainCoin",200,chainCoin);
     	.wait(chainCoin(Coin));
     	.broadcast(tell,cryptocurrency(Coin));
     	.broadcast(tell,bankWallet(PuK));  
     	.broadcast(tell,chainServer(Server));
     .
    
     +!lending(ResquestNumber,ClientWallet,Value)[source(Client)]
     : chainCoin(Coin)   
     & myWallet(Prk,PuB)     
     & chainServer(Server) <-
     	.print("Hello Agent ",Client,", Wellcome to BanChain! - Please wait while we check the transaction.");
     	.velluscinum.stampTransaction(Server,Prk,PuB,ResquestNumber,loan(Client));
     	.velluscinum.transferToken(Server,Prk,PuB,Coin,ClientWallet,Value,transactionTransfer);
     	.send(Client,tell,bankAccount(ok)); 
     .
    
  • Create the file chefBankGlutton/src/agt/chef.asl with the below:

    Agent chef content file
     // Agent chef in project chefBankGlutton
     /* Initial beliefs and rules */
     lastOrder(0).
    
     /* Initial goals */
     !createWallet.
    
     /* Plans */
     +!createWallet <-
     		.print("Creating a digital wallet!");
     		.velluscinum.buildWallet(myWallet);
     		.wait(myWallet(Priv,Pub));
     		+chefWallet(Pub);
     .
     
     +!order(Product,Qtd,Payment)[source(Client)]: cryptocurrency(Coin)
     						& chainServer(Server) & myWallet(MyPriv,MyPub) <-
     		?lastOrder(N);
     		OrderNr=N+1;
     		-+lastOrder(OrderNr);
     		.print("Received the order",OrderNr," ckecking payment...");
     		.velluscinum.stampTransaction(Server,MyPriv,MyPub,Payment,payment(OrderNr));
     		+preparingOrder;
     		!cooking(OrderNr,Product,Qtd,Client);
     		-preparingOrder;
     .
     
     +!cooking(OrderNr,Product,Qtd,Client) <-
     		.print("Preparing order Nr ",OrderNr);
     		.wait(1000);
     		.send(Client,tell,delivering(Product,Qtd));
     .
    
  • Create the file chefBankGlutton/src/agt/glutton.asl with the content below:

    Agent glutton content file
     // Agent glutton in project chefBankGlutton
     /* Initial beliefs and rules */
     foodStock(10).
     energy(0).
    
     /* Initial goals */
     !enjoy.
    
     /* Plans */
     +!requestLend: cryptocurrency(Coin) & bankWallet(BankW) & chainServer(Server) & myWallet(MyPriv,MyPub)<-
     		.print("Requesting Lend");
     		.velluscinum.deployNFT(Server,MyPriv,MyPub,
     								"name:comilao;address:5362fe5e-aaf1-43e6-9643-7ab094836ff4",
     								"description:Createing Bank Account",
     								account);
     		.wait(account(AssetID));
     		.velluscinum.transferNFT(Server,MyPriv,MyPub,AssetID,BankW,
     								"description:requesting lend;value_chainCoin:10",requestID);
     		.wait(requestID(PP));
    
     		.print("Lend Contract nr:",PP);
     		.send(bank,achieve,lending(PP,MyPub,10)).
    
     +!eat: hungry & foodStock(C) & C>3 & energy(E) & E<=10 <-
     		-+foodStock(C-3);
     		-+energy(E+3);
     		.print("Eating........ [Fridge=",C-3,"] [Energy=",E+3,"]");
     		.wait(1000);
     		!eat.
    
     +!eat: energy(E) & E>10 <-
     		.print("Satisfied...... [Energy=",E,"]");
     		-hungry;
     		!enjoy.
    
     +!eat <-
     		?foodStock(X);
     		.print("I need food..... [Fridge=",X,"]");
     		.wait(1000);
     		!orderFood.
    
     +!enjoy: energy(E) & E>5 <-
     		.print("Enjoying....");
     		.wait(1000);
     		-+energy(E-3);
     		-hungry;
     		!enjoy.
    
     +!enjoy: energy(E) & E<=5<-
     		.print("Tired..... [Energy=",E,"]");
     		+hungry;
     		!eat.
    
     +!orderFood: bankAccount(ok)[source(bank)] & cryptocurrency(Coin) 
     						& chainServer(Server) & myWallet(MyPriv,MyPub) 
     						& chefWallet(Chef)<-
    
     		.print("Ordering food.....");
     		.velluscinum.transferToken(Server,MyPriv,MyPub,Coin,Chef,5,payment);
     		.wait(payment(Transfer));
     		.send(chef,achieve,order(pizza,5,Transfer));
     		.wait(5000);
     		!eat.
    
     +!orderFood: not bankAccount(ok)[source(bank)] <-
     		.wait(5000);
     		.velluscinum.buildWallet(myWallet);
     		!requestLend;
     		.wait(5000);
     		.send(chef,askOne,chefWallet(Chef),Reply);
     		+Reply;
     		!orderFood.
    
     -!orderFood: cryptocurrency(Coin) & chainServer(Server) 
     				& myWallet(MyPriv,MyPub) <-
     				.velluscinum.tokenBalance(Server,MyPriv,MyPub,Coin,balance).
    
     +delivering(Product,Qtd)[source(Chef)] <-
     		?foodStock(X);
     		-+foodStock(X+Qtd);
     		.print("Wow! Pizza!!!!");
     		-delivering(Product,Qtd)[source(Chef)].
    
     +balance(T,V)[source(self)]: cryptocurrency(Coin)[source(bank)] & V<5 & Coin==T <-
     		.drop_desire(enjoy);
     		.print("I don't have money! :(");
     		.wait(5000).
    
    

Runing

jacamo chefBankGlutton/chefBankGlutton.jcm