/js-client

javascript client

Primary LanguageJavaScript

js client

javascript client that communicate with aicup kernel

how to run

  1. first make sure you have nodejs installed on your computer.
    you can download it from the official website : https://nodejs.org/en/download
  2. download the repository and unzip it then open the terminal and use cd command to go to the project's directory
  3. run npm install to install all the project's dependencies
  4. run the kernel web-server and then set server_ip and server_port of the web-server in config.js file
  5. put your code and logic for the game in functions inside main.js ( a sample code already exist in this file you can check it to learn how your code should be )
  6. finally run npm start to run the client

description

game object is passed to both initilizer and turn function in main.js and you should write your code withing these functions .
game object has some methods which are all marked as async so they return a promise and you should use await keyword everywhere you use them .
all of the methods will throw exception if there is an error , so it's better to wrap each of the method in try catch blocks to handle the errors and prevent the program from crashing .

game object methods list :

method name description success result example
get_owners() this method is used to get the owners of all nodes.
-1 means node has no owner.
other numbers are the player_id of the owner.
{
  "1" : -1,
  "2" : -1,
  "3 : 0,
  "4" : 1,
  "5" : -1,
}
get_strategic_nodes() this method is used to get the list of strategic nodes and their coresponding score
so for example the score of the node in index 2 is the value of score array in index 2
{
   score: [ 2, 1, 5, 4, 1, 3 ],
   strategic_nodes: [ 3, 4, 7, 20, 29, 40 ]
}
get_turn_number() this method return the current turn number
{
    turn_number: 5
}
get_adj() return an object with the node's as key and array of adjecent nodes with that node
{
  '0': [ 1, 2 ],
  '1': [ 0, 2, 3 ],
  '2': [ 0, 1, 3 ],
  '3': [ 1, 2, 4 ],
  '4': [ 3, 5, 6 ],
  '5': [ 4, 6, 8, 7, 14, 13 ],
  '6': [ 4, 5, 7, 21 ],
}
get_number_of_troops_to_put() the number of troops that you own but you havn't place them on any node
{
number_of_troops: 12
}
put_one_troop(node_id) this method is used to put one troop inside the node_id { message : "troop added successfully" }
put_troop(node_id , number) this method is used to put number troop inside the node_id { message : "troop added successfully" }