OpenHoldem:EndUserDocumentation:ScriptingLanguage

From Maxin Wiki

Jump to: navigation, search

Contents

[edit] Introduction

OpenHoldem's scripting language is very similar to the C programming expression syntax. If you already know and understand C programming then you have an advantage in that the OH scripting language should be very familiar.

This Wiki page is largely based off of Ray Bornert's original WinHoldem "C-tutorial" here: http://www.winholdem.net/help/help-c.html


[edit] Syntax

The general syntax for OpenHoldem formulas is same as that of the C programming language. The formulas are strict R-VALUES (right side of an assignment expression). There is no assignment operator. All values are stored as (double) floating point values on the expression stack. For bitwise operations the values are first converted to (int) and then the operator is applied.


[edit] Boolean Logic

A boolean expression is composed of logical operators (not, and, or, xor) and operands. All boolean operands have only two values - true and false. Each logical operand has a very well defined operation upon the operand(s) in the expression, with a very well defined result. When any numeric value is used in conjunction with a logical operator, any zero values are considered to be false (0) and any non-zero values are considered to be true (1). If the numeric value in question is not zero then it is considered to be true for boolean purposes.

Reams of material have been written on boolean logic. Example: http://en.wikipedia.org/wiki/Boolean_logic


[edit] Operators

These operators are listed in order of precedence

Category Operator(s) Associativity
Exponentiation ** ln (not standard ANSI C) Right to Left
Unary ! ~ - ` Right to Left
Multiplicative * / % Left to Right
Additive + - Left to Right
Bitwise Shift << >> Left to Right
Relational < > <= >= Left to Right
Equality == != Left to Right
Bitwise AND & Left to Right
Bitwise XOR ^ Left to Right
Bitwise OR pipe (above forward slash on U.S. keyboard) Left to Right
Logical AND && Left to Right
Logical XOR ^^ (not standard ANSI C) Left to Right
Logical OR double pipe (above forward slash on U.S. keyboard) Left to Right
Conditional ?: Right to Left
Group () [] {} (not standard ANSI C) Left to Right


[edit] Exponentiation

[edit] Power ** (not ANSI-C)

a ** b

Standard algebraic exponentiation on a and b.

a is raised to the power of b.

[edit] Natural Log ln (not ANSI-C)

ln a

Standard algebraic natural log of a

a == e ** (ln a)

[edit] Natural Log Base e (not ANSI-C)

e == ln(1)

e == 2.71828182845905


[edit] Unary

A unary operator takes a single operand.

[edit] Logical NOT !

False when the operand is true. True when the operand is false.

a  !a
false true
true false
0 1


[edit] Bitwise NOT ~

Logical NOT operation on a bit by bit basis.

expression binary result
a 11001001011101010110010101111010
~a 00110110100010101001101010000101


[edit] Negation -

A good example is the minus sign when it is used to alter the sign of a value. Example: "a + b / -4" The minus sign in front of the 4 is a unary minus.


[edit] Bit Count ` (not ANSI-C)

Provides a count of the number of bits set in any integer value. Here are 3 examples of the number of bits that are set in some 32-bit integer numbers.

a `a
0000000000000000000000000000000 0
0000000000000100000000000000000 1
0000010000000100000000000010000 3
1111111111111111111111111111111 32


[edit] Multiplicative

[edit] Multiply *

a * b

Standard algebraic multiplication on a and b.

[edit] Divide /

a / b

Standard algebraic division on a and b.

[edit] Modulo %

a % b

Standard algebraic modulo on a and b.


[edit] Additive

[edit] Add +

a + b

Standard algebraic addition on a and b.

[edit] Subtract -

a - b

Standard algebraic subtraction on a and b.


[edit] Bitwise Shift

[edit] Bitwise Shift Left <<

Slides the entire bit pattern to the left by N bits. Note that the leftmost bits are simply dropped and that the rightmost bits are filled with 0's. The shift magnitude is used as modulo 32, meaning that any shift N that is specified in excess of 32 bits has a N%32 operation performed prior to the shift.

expression binary result
a 11001001011101010110010101111010
a<<1 10010010111010101100101011110100
a<<7 10111010101100101011110100000000
a<<31 00000000000000000000000000000000
a<<32 11001001011101010110010101111010

[edit] Bitwise Shift Right >>

Slide the entire bit pattern to the right by N bits. Note that the rightmost bits are dropped and that the leftmost bits are filled with the leftmost bit of the operand. The shift magnitude is used as modulo 32, meaning that any shift N that is specified in excess of 32 bits has a N%32 operation performed prior to the shift.

expression binary result
a 11001001011101010110010101111010
a>>1 11100100101110101011001010111101
a>>7 11111111100100101110101011001010
a>>31 11111111111111111111111111111111
a>>32 11001001011101010110010101111010
a 01001001011101010110010101111010
a>>1 00100100101110101011001010111101
a>>7 00000000100100101110101011001010
a>>31 00000000000000000000000000000000
a>>32 01001001011101010110010101111010


[edit] Relational

[edit] Less Than <

a b a < b
-1 0 true
0 0 false
+1 0 false

[edit] Greater Than >

a b a > b
-1 0 false
0 0 false
+1 0 true

[edit] Less Than Or Equal <=

a b a <= b
-1 0 true
0 0 true
+1 0 false

[edit] Greater Than or Equal >=

a b a >= b
-1 0 false
0 0 true
+1 0 true


[edit] Equality

[edit] Equal ==

a b a == b
-1 0 false
0 0 true
+1 0 false

[edit] Not Equal !=

a b a != b
-1 0 true
0 0 false
+1 0 true


[edit] Bitwise AND &

Logical AND operation on a bit by bit basis.

expression binary
a 11001001011101010110010101111010
b 01001010010100101110001010101111
a&b 01001000010100000110000000101010


[edit] BITWISE OR |

Logical OR operation on a bit by bit basis.

expression binary
a 11001001011101010110010101111010
b 01001010010100101110001010101111
b 11001011011101111110011111111111

[edit] Bitwise XOR ^

Logical XOR operation on a bit by bit basis.

expression binary
a 11001001011101010110010101111010
b 01001010010100101110001010101111
a^b 10000011001001111000011111010101


[edit] Logical AND &&

False when any operand is false. True when both operands are true.

a b a && b
false false false
false true false
true false false
true true true


[edit] Logical XOR ^^ (not ANSI-C)

False when operands are boolean equal. True when operands are not boolean equal. Note that "a^^b" is equivalent to "(a!=0)^(b!=0)".

a b a ^^ b
false false false
false true true
true false true
true true false


[edit] Logical OR ||

False when both operands are false. True when any operand is true.

a b a pipe-pipe b
false false false
false true true
true false true
true true true


[edit] Conditional ?:

Standard algorithmic if then else. "a ? b : c" means "If a then b else c"

a b c a ? b : c
true any any b
false any any c


[edit] Grouping Operators ()[]{}

Note that [] and {} are not ANSI-C.

These grouping operators are used to either visibly separate sections of your code for readability and maintainability purposes, or to affect the precedence of logical operation. Note that unlike WinHoldem's grouping syntax, there is *no* limitation on how the various grouping operators can be nested.


[edit] Numeric Constants

[edit] Floating point constants

All numeric constants are treated internally as double floating point values in base 10.

Floating Point Numeric Constants
123.456
0.987
192837465
.5
17.
5.4321e-76


[edit] Integer constants

There are 4 integer options available as well that allow you to select the base of the constant. The 4 available bases are: 16, 8, 4, 2. Prefixing a numeric constant with a zero followed by a letter (see table below) will specify the numeric base of the constant.

Letter Base Name
x 16 Hex
o 8 Octal (non-standard ANSI C)
q 4 Quadal (non-standard ANSI C)
b 2 Binary (non-standard ANSI C)

Examples:

Decimal Hex Octal Quadal Binary
0 0x0 0o0 0q0 0b0
1 0x1 0o1 0q1 0b1
2 0x2 0o2 0q2 0b10
3 0x3 0o3 0q3 0b11
4 0x4 0o4 0q10 0b100
5 0x5 0o5 0q11 0b101
6 0x6 0o6 0q12 0b110
7 0x7 0o7 0q13 0b111
8 0x8 0o10 0q20 0b1000
9 0x9 0o11 0q21 0b1001
10 0xa 0o12 0q22 0b1010
11 0xb 0o13 0q23 0b1011
12 0xc 0o14 0q30 0b1100
13 0xd 0o15 0q31 0b1101
14 0xe 0o16 0q32 0b1110
15 0xf 0o17 0q33 0b1111
16 0x10 0o20 0q100 0b10000
31 0x1f 0o37 0q133 0b11111
63 0x3f 0o77 0q333 0b111111
127 0x7f 0o177 0q1333 0b1111111
255 0xff 0o377 0q3333 0b11111111

[edit] See also

Personal tools