8000 GitHub - emiljapelt/trench: Programming PvP game
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

emiljapelt/trench

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

╶┬╴                                 
 │ ┌╴ ┌─┐         ╷                 
 │ │  │ │         │                 
 │ ╵  ├─┘     ┌─╴ ├─┐               
 ╵    │   ╷   │   │ │               
      └─╴ ├─┐ └─╴ ╵ ╵               
          │ │                       
          ╵ ╵            

File extensions

.tr Source code for a players behavior
.trg A trench game setup file

The Trench Language

The code written for a player character is called a directive and it consist of a series of statements, which will be executed from the top. Each statement takes some 'steps' to execute and some also requires some 'actions' to execute. A limit to how many 'steps' and 'actions' can be taken in a turn, is set in the game rules.

Execution mode

The execution mode defines how the game is executed, how a round progress and when what happens. There currently exists 2 modes.

Async execution

In this mode each player takes turns executing their directive. Once every player has had a chance to execute, a round has completed. During a turn a player will have a predefined number of steps and actions they are allowed to take, and their turn end when they try to take a step/action but cannot.

Sync execution

In this mode player effectivly take turns at the same time. This is done by splitting the round into phases:

  • Step phase: Player execute their program, until they reach an action/move.
  • Defensive phase: Players that reached a defensive action take their action.
  • Offensive phase: Players that reached an offensive action take their action.
  • Movement phase: Players that reached a move take their action.

After all phases are complete, a round has passed. The number of actions available is ignored in the mode.

Feature levels

The features of the trench language are split into 4 levels. Lower levels means a more restricted set of features.

  • Level 0: Core features (move, shoot, trench, labels, goto, ...)
  • Level 1: Memory features (variables, assignments, global array, ...)
  • Level 2: Basic features (if-else, repeat, random, ...)
  • Level 3: Advanced features (loops, switches, ...)

Statements

statement explaination examples actions steps
type a declaration int a; 0 1
type a = v declaration with assignment int a = 2; 0 1 + v
if c a else b conditional execution if x { ... } else { ... } 0 c + a + 1, or c + b + 2
if c a conditional execution if (? % 2) { ... } 0 c + a + 1, or c + 2
{s0 ... sn} A contained series of statements. { ... } 0 s0 + ... + sn
repeat x s Compile a statement 'x' times repeat 2 move N; 0 x * s
while c s Execute s as long as c is non-zero while 1 move E; 0 _
break Break out of the current loop break; 0 1
continue Start the next iteration of the current loop continue; 0 1
a = e Assign a value to a variable. a = a + 1; a += 1; 0 e + 2
type [ a ] = e Assign a value to the global type array int[4] = 2 + 2; 0 a + e + 2
label: Marks a location in the directive loop: 0 0
move d Move the player 1 space in some direction. move [N,S]; 0 d + 1
shoot d Shoot in some direction, from the players current position. Any player in that direction, not in a trench will die. shoot S; 1 d + 1
bomb d p Throw a bomb in some direct, some number of spaces. It explodes after 1 round, killing any player hit, unless they are in a fortified trench. Fortified trenches become unfortifed, unfortified trenches are destroyed. bomb N (2+1); 1 d + p + 1
mine d Place a mine in some direct. It explodes if anyone steps of it, killing that player. mine N; 1 d + 1
fortify Fortify the trench here, if there is a trench. fortify; 1 2
fortify d Fortify the trench in some direction, if there is a trench. fortify N; 1 d + 1
trench Dig a trench here. trench; 1 2
trench d Dig a trench in some direction. trench W; trench; 1 d + 1
wait Use an action on nothing. wait; 1 1
pass End the current turn. pass; 0 1
goto Jump to a location in the directive. goto loop; 0 1

Values

value explaination examples steps
x reference to a variable 'x' counter 1
#x reference to a meta variable 'x' #x 1
type [ a ] reference an index in the global type array int[2] a + 2
i interger value 14, -1 1
d cardinal direction N, E, S, W 1
a binop b binary operation 1 + 2, x % 10, N + 1 a + b + 1
unop a unary operation ~a a + 1
scan d a Get field information of the field in direction d, distance i scan N 2; d + a + 1
a.f Get a part of some field information (scan N 2).PLAYER a + 1
look d get the distance to the closest trench in some direction, or 0 if there is none look N d + 1
? Get a random positive integer ? 1
?(e0 ... en) pick a random value from a list ?(N S) ?(1, (2*12)) e0 + ... + en + 1

binary operators: +, -, *, /, %, >, >=, <, <=, !=, =, |, &

unary operators: ~ (not)

meta variable explaination
#x players 'x' position
#y players 'y' position
#bombs players remaining bombs
#shots players remaining shots
#board_x board width
#board_y board height
#array_size global array size
field info explaintion
PLAYER The field has a player
TRENCH The field is trenched
MINE The field has a mine
DESTROYED The field is destroyed

Game setup files

The game file specifies the players and rules of a particular game. It consists of key value pairs, seperated by semi-colons, defining a set of values. Pairs can be left out, in which case a default will be used.

key explaination
bombs the number of bombs a player can throw in a game
shots the number of shots a player can fire in a game
actions the number of actions a player can take per turn
steps the number of steps a player can can perform per turn
mode the number of round that must pass before players can change directive, 0 meaning never. Any negative number meaning before every turn.
player the id, x and y position, and source file of a player
board_x the board width
board_y the board height
nuke how many rounds must pass, between every space on the board being blow up. 0 meaning never.
global_array the size of each global array
feature_level set the maximum allowed feature level
exec_mode Can be either async or sync

In the following, every value is set to its default, except the player:

bombs:10;
shots:100;
actions:1;
steps:100;
mode:0;
nuke:0;
global_array: 10;
feature_level: 3;
exec_mode: async;

board_x:20;
board_y:20;

player:1,(5,5),./player1.tr;
player:2,(8,9),./player2.tr;

About

Programming PvP game

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0