Skip to content

Instantly share code, notes, and snippets.

@zlumer
Last active July 21, 2018 23:00
Show Gist options
  • Save zlumer/cf51be1721f087d0dfa4777cdcea4fb5 to your computer and use it in GitHub Desktop.
Save zlumer/cf51be1721f087d0dfa4777cdcea4fb5 to your computer and use it in GitHub Desktop.
expload/pravda regression

Contract compiles successfully both in csc and pravda dotnet but fails to deploy on local node.

Stopping abci.socketClient for error: read tcp 127.0.0.1:59507->127.0.0.1:46658: wsarecv: An existing connection was forcibly closed by the remote host. module=abci-client connection=mempool

Compilation:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe poker.cs /reference:../pravda/dotnet/src/test/resources/expload.dll 
pravda compile dotnet --input poker.exe --output poker.pravda

Deployment:

pravda broadcast deploy -w ../testnet/my-wallet.json -i poker.pravda -l 100000
using System;
using Com.Expload;
[Program]
class MyProgram
{
private int get_suit(int card)
{
// 0 = spades
// 1 = clubs
// 2 = hearts
// 3 = diamonds
return card - (card % 20);
}
private int get_value(int card)
{
// 0 = 2
// 1 = 3
// ...
// 8 = 10
// 9 = J
// 10 = Q
// 11 = K
// 12 = A
return card % 20;
}
private int CARD_VAL_2 = 0;
private int CARD_VAL_A = 12;
public int get_combination_value(int c0, int c1, int c2, int c3, int c4)
{
// if (isRoyalFlush(cards)) // royal flush doesn't mean shit because it's just a straight flush with highest card Ace
// return 65000;
int cv0 = get_value(c0);
int cv1 = get_value(c1);
int cv2 = get_value(c2);
int cv3 = get_value(c3);
int cv4 = get_value(c4);
// High cards by rank
return 5 * cv4 + 4 * cv3 + 3 * cv2 + 2 * cv1 + cv0;
}
// ###### ####### ## ## ######## ######
// ## ## ## ## ### ### ## ## ## ##
// ## ## ## #### #### ## ## ##
// ## ## ## ## ### ## ######## ######
// ## ## ## ## ## ## ## ##
// ## ## ## ## ## ## ## ## ## ##
// ###### ####### ## ## ######## ######
private bool isFourOfAKind(int c0, int c1, int c2, int c3, int c4)
{
// optimized version (cards are sorted by value already)
if ((c0 == c1)
&& (c0 == c2)
&& (c0 == c3))
return true;
if ((c4 == c1)
&& (c4 == c2)
&& (c4 == c3))
return true;
return false;
}
private bool isFlush(int c0, int c1, int c2, int c3, int c4)
{
int suit = get_suit(c0);
return (suit == get_suit(c1))
&& (suit == get_suit(c2))
&& (suit == get_suit(c3))
&& (suit == get_suit(c4))
;
}
private bool isStraightSimple(int c0, int c1, int c2, int c3, int c4)
{
if (c0 != (c1 - 1))
return false;
if (c0 != (c2 - 2))
return false;
if (c0 != (c3 - 3))
return false;
if (c0 != (c4 - 4))
return false;
return true;
}
private bool isStraight(int c0, int c1, int c2, int c3, int c4)
{
// 5,6,7,8,9
// 2,3,4,5,A
// 10,J,Q,K,A
// straights can't wrap around (2,3,4,K,A is not a straight)
if (isStraightSimple(c0, c1, c2, c3, c4))
return true;
if (c0 != CARD_VAL_2)
return false;
if (c4 != CARD_VAL_A)
return false;
if ((c1 == (c0 + 1))
&& (c2 == (c0 + 2))
&& (c3 == (c0 + 3)))
return true;
if ((c4 == (c3 + 1))
&& (c4 == (c2 + 2))
&& (c4 == (c1 + 3)))
return true;
return false;
}
// Three of a kind
private bool isThreeOfAKind(int c0, int c1, int c2, int c3, int c4)
{
if ((c0 == c1)
&& (c0 == c2))
return true;
if ((c1 == c2)
&& (c1 == c3))
return true;
if ((c2 == c3)
&& (c2 == c4))
return true;
return false;
}
}
class MainClass
{
public static void Main() {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment