Shuffly-Brain is a project mainly written in C#, it's free.
The core of the shuffly system, compiler and virtual machine for the spoke language.
Any Card Game codename Shuff.ly As described by Dested
Information
Spoke Specification
Structure
Code is structured in a strict tabbed format
Classes and Enums are always at tab index 0
Methods defintions are always at tab index 1 and method content are always at tab index 2
Code blocks are denoted by increased tab index
Keywords
def,class,create,switch,enum,return,static,this,if,else,false,true
Operators
Arithmetic
Logical
&& || !
Increment, Decrement
++ --
Relational
== != < > <= >=
Assignment
= += -= *= /=
Field access
.
Anonymous method
=>
Indexing arrays
[ ]
Ternary conditional
bool?val1:val2
Both values must be of equal type
Object creation
create
Literals
float
1.4,-402.4234
int
1,5,80,-120
string
\
bool
true,false
Arrays
Arrays are instantiated by simply using [] and can contain any number of values as long as they are of the same type
a=[]
a=[1,3,5,8]
a=[create {X=5,Y=10},create {X=12,Y=15}]
Arrays have a full list of methods to allow manipulation, some of which have compiler instruction calls tied to them (Add, Remove, GetElement, SetElement)
Classes
Classes have a case sensitive name
class ClassName
They are made up of Fields and Methods
Fields are defined simply as name=value, and must be assigned a default value
Foo=create Bar()
Amount=0.0
Methods are defined as def name(paramaters)
def Foobar(foo,bar) print(foo) print(bar)
Static methods have type information along with them
def static Foobar(int foo,int bar)
Methods are not polymorphic
Objects
An object can be a predefined class with methods and fields, or defined at time of use with only fields. Class instantiation can also take any number of parameters defined in the constructor.
create Foobar(15) , create {Foo=6,Bar=9}
Objects are considered of the same type so long as they contain the same field thumbprint (defined as type and name)
An object can be set to null, but an object cannot be set to null initially.
To set an object to null while still defining the type use
type Foobar , type {Foo=type int, Bar=type int}
Only objects of the same type can be compared
if create {X=5,Y=12}==create {X=5,Y=11} # will compile
if create {X=5,Y=12}==create {X=5,Y=11,Z=12} # will not compile
Methods
Methods can be called on an object using dot notation. Inside of methods the developer is allowed to use the special variable this to denote the current object.
variable.someMethod(6)
this.someMethod(6)
someMethod(6) # from within the same class
Static methods do not allow this and are called by using the class name
Foobar.someMethod(6)
Variables
Variable Naming
Case Sensitive
Cannot start with number
Cannot be keywords
Variables types are defined at the time of instantiation, its type cannot change through the lifetime of the application
Types
int, float,bool,array, an object
Variable types only need to be defined in the the header of static methods, they are assumed by declaration after that point
Anonymous Methods
Anonymous methods are denoted using =>, parameters are only used when neccecary
variable => |(parameter1,parameter2)
They are used for loops as well as passing around chunks of code.
Loop
Loops can be triggered on by either a boolean conditional (traditional while loop), or an array (traditionally foreach loop)
[1,2,4,6]=>|(value) print(value) # 1 2 4 6
[1,2,4,6]=>|(value,index) print(index) # 0 1 2 3 print(value) # 1 2 4 6
[1,2,4,6]=>variable # where variable is an anonymous # method with thethumbprint of one or # two int parameters
They can be set to variables. When doing this they maintain the variable scope in which they were declared.
variable = |(value,index)=> print(value) print(index)
Conditional structures
If statement (with optional else and else if)
if i==3
else if i==5
else
Ternary
variable = (i==3)?12:19
Switch structures
switched on variables can be of any type.
fall through is not allowed unless the codeblock is empty
switch (variable) case 1:
case 2:
#code block
case 3:
case 4:
#code block
Enums
Enum items can be set to a value of any type
Enum Priority High=1 Medium=2 Low=3
Library definition
Package SpokeLibrary
Class Rectangle int x int y int width int height
Class Randomizer (int seed) int next() int nextBetween(int left,int right)
Class Math float pi float sin(float s) float cos(float s) float tan(float s)
Class Array void add(Any object) void addRange(Any[] objects) void remove(Any object) bool contains(Any object) int length() Any elementAt(int index) void setElement(int index,Any object) int indexOf(Any object) void clear()
Enum Order NoOrder,Ascending,Descending
Package ACGFramework
Class CardGame (int numberOfCards, int numberOfJokers) User[] users Pile[] piles Pile deck TableArea mainArea TableArea[] userAreas void dealCards(int numberOfCards,CardState state)
Class User string userName int playerDealingOrder Card[] cards
Class Pile Card[] cards void shuffle()
Class Card int value CardType type bool faceUp CardState state String getFullName() String getValueName() String getTypeName()
Enum CardState FaceUp,FaceDown,FaceUpIfOwned
Enum CardType Heart,Diamond,Spade,Club
Class PokerRules PokerResult[] evaluatePoker(Cards[] cards)
Class PokerResult Card[] cards PokerWinType type int weight
Enum PokerWinType Straight,Flush,Pair,ThreeOfAKind,FourOfAKind,StraightFlush
Package LayoutFramework
Class TableArea int numberOfCardsHorizontal int numberOfCardsVertical Rectangle dimensions TableSpace[] spaces TableTextArea[] textAreas
Class TableSpace bool visible bool stackCards bool drawCardsBent string name string areaName int xPosition int yPosition int width int height Order sortOrder
Class TableTextArea string name string areaName int xPosition int yPosition int rotateAngle string text