Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <time.h>
- #include "Game_Api.h"
- using json = nlohmann::json;
- using Player = Game_Api::Player;
- using Monster = Game_Api::Monster;
- using DeathEffects = Game_Api::DeathEffects;
- #define RESPONSE_SECS 1
- #define RESPONSE_NSECS 0
- #include <iostream>
- using namespace std;
- //Globals
- Game_Api * api;
- int my_player_num = 0;
- string get_beating_stance(string stance){
- if (stance == "Rock")
- return "Paper";
- if (stance == "Paper")
- return "Scissors";
- return "Rock";
- }
- // sorts list such that it is highest to lowest Example {10,-1,8,0,6,1,4,2,3} -> {10,8,6,4,3,2,1,0,-1}
- bool compare_rock_value(Monster a, Monster b)
- {
- return a._death_effects._rock > b._death_effects._rock;
- }
- // sorts list such that it is highest to lowest Example {10,-1,8,0,6,1,4,2,3} -> {10,8,6,4,3,2,1,0,-1}
- bool compare_paper_value(Monster a, Monster b)
- {
- return a._death_effects._paper > b._death_effects._paper;
- }
- // sorts list such that it is highest to lowest Example {10,-1,8,0,6,1,4,2,3} -> {10,8,6,4,3,2,1,0,-1}
- bool compare_scissors_value(Monster a, Monster b)
- {
- return a._death_effects._scissors > b._death_effects._scissors;
- }
- // sorts list such that it is highest to lowest Example {10,-1,8,0,6,1,4,2,3} -> {10,8,6,4,3,2,1,0,-1}
- bool compare_speed_value(Monster a, Monster b)
- {
- return a._death_effects._speed > b._death_effects._speed;
- }
- class decision_maker {
- private:
- unsigned int amount_of_hardcoded_sequences = 5;
- unsigned int current_sequence = 0;
- unsigned int enemies_last_location = 0;
- std::vector<node_id_t> location_vector = {10, 11, 12, 22, 21, 20};
- std::vector<int > duration_vector = { 7, 7, 7, 7, 7, 8};
- std::vector<int > enemy_path_vector;
- void log_enemy_path()
- {
- if(api->get_opponent()._location != enemies_last_location)
- {
- enemy_path_vector.push_back(api->get_opponent()._location);
- enemies_last_location = api->get_opponent()._location;
- }
- }
- vector<Monster> get_rock_monsters()
- {
- vector<Monster> monster_vector = api->get_all_monsters();
- vector<Monster> rock_monsters;
- std::sort (monster_vector.begin(), monster_vector.end(), compare_rock_value);
- for(Monster& monster : monster_vector)
- {
- if(monster._death_effects._rock > 0)
- {
- rock_monsters.push_back(monster);
- }
- }
- return rock_monsters;
- }
- vector<Monster> get_paper_monsters()
- {
- vector<Monster> monster_vector = api->get_all_monsters();
- vector<Monster> paper_monsters;
- std::sort (monster_vector.begin(), monster_vector.end(), compare_paper_value);
- for(Monster& monster : monster_vector)
- {
- if(monster._death_effects._paper > 0)
- {
- paper_monsters.push_back(monster);
- }
- }
- return paper_monsters;
- }
- vector<Monster> get_scissors_monsters()
- {
- vector<Monster> monster_vector = api->get_all_monsters();
- vector<Monster> scissors_monsters;
- std::sort (monster_vector.begin(), monster_vector.end(), compare_scissors_value);
- for(Monster& monster : monster_vector)
- {
- if(monster._death_effects._scissors > 0)
- {
- scissors_monsters.push_back(monster);
- }
- }
- return scissors_monsters;
- }
- vector<Monster> get_speed_monsters()
- {
- vector<Monster> monster_vector = api->get_all_monsters();
- vector<Monster> speed_monsters;
- std::sort (monster_vector.begin(), monster_vector.end(), compare_speed_value);
- for(Monster& monster : monster_vector)
- {
- if(monster._death_effects._speed > 0)
- {
- speed_monsters.push_back(monster);
- }
- }
- return speed_monsters;
- }
- bool is_enemy_near_24()
- {
- return (enemy_path_vector.back() == 24) || (enemy_path_vector.back() == 23) || (enemy_path_vector.back() == 19);
- }
- bool is_enemy_near_1_speed()
- {
- return (enemy_path_vector.back() == 0) || (enemy_path_vector.back() == 1) || (enemy_path_vector.back() == 4) || (enemy_path_vector.back() == 2) || (enemy_path_vector.back() == 3);
- }
- bool is_speed_1_monster_alive()
- {
- vector<Monster> speed_monsters = get_speed_monsters();
- if((speed_monsters.front()._death_effects._speed == 1)||(speed_monsters.back()._death_effects._speed == 1))
- {
- return true;
- }else{
- return false;
- }
- }
- bool early_midgame_decision_switch_flag = false;
- void early_midgame_decision_switch()
- {
- if(early_midgame_decision_switch_flag == true)
- {
- return;
- }
- if(is_enemy_near_24() == true)
- {
- rush_1_speed_setup();
- }else if(!is_enemy_near_1_speed() && is_speed_1_monster_alive()){
- rush_1_speed_setup();
- }else{
- rush_24_setup();
- }
- early_midgame_decision_switch_flag = true;
- }
- void rush_24_setup()
- {
- location_vector.push_back(19);
- duration_vector.push_back(8);
- location_vector.push_back(23);
- duration_vector.push_back(5);
- location_vector.push_back(24);
- duration_vector.push_back(6);
- location_vector.push_back(23);
- duration_vector.push_back(6);
- location_vector.push_back(19);
- duration_vector.push_back(5);
- location_vector.push_back(22);
- duration_vector.push_back(5);
- location_vector.push_back(12);
- duration_vector.push_back(5);
- location_vector.push_back(13);
- duration_vector.push_back(5);
- location_vector.push_back(20);
- duration_vector.push_back(5);
- location_vector.push_back(21);
- duration_vector.push_back(3);
- api->log("24 lv size "+to_string(location_vector.size()));
- }
- void rush_1_speed_setup()
- {
- location_vector.push_back(13);
- duration_vector.push_back(8);
- location_vector.push_back(4);
- duration_vector.push_back(6);
- location_vector.push_back(2);
- duration_vector.push_back(5);
- location_vector.push_back(3);
- duration_vector.push_back(4);
- location_vector.push_back(1);
- duration_vector.push_back(4);
- location_vector.push_back(0);
- duration_vector.push_back(4);
- location_vector.push_back(10);
- duration_vector.push_back(4);
- location_vector.push_back(16);
- duration_vector.push_back(4);
- location_vector.push_back(15);
- duration_vector.push_back(4);
- location_vector.push_back(18);
- duration_vector.push_back(4);
- location_vector.push_back(17);
- duration_vector.push_back(4);
- location_vector.push_back(16);
- duration_vector.push_back(4);
- location_vector.push_back(12);
- duration_vector.push_back(4);
- location_vector.push_back(22);
- duration_vector.push_back(4);
- location_vector.push_back(21);
- duration_vector.push_back(2);
- api->log("1s lv size "+to_string(location_vector.size()));
- }
- public:
- node_id_t get_current_command_location() // -1 signifies there is no valid hardcoded path
- {
- node_id_t location = -1;
- log_enemy_path();
- if(api->get_turn_num() <= 43)
- {
- location = run_decision_tree();
- }else if (api->get_turn_num() <= 150){ // TODO
- early_midgame_decision_switch();
- location = run_decision_tree();
- }
- return location;
- }
- node_id_t run_decision_tree()
- {
- //if(current_sequence >= amount_of_hardcoded_sequences)
- //{
- // return -1;
- //}
- if(duration_vector[current_sequence] == 0)
- {
- current_sequence++;
- }
- //if(current_sequence >= amount_of_hardcoded_sequences)
- //{
- // return -1;
- //}
- duration_vector[current_sequence]--;
- if (duration_vector[current_sequence] < 7 - api->get_self()._speed)
- return location_vector[current_sequence];
- return api->get_self()._location;
- }
- };
- decision_maker dm;
- void strategy(){
- Player me = api->get_self();
- Player opponent = api->get_opponent();
- int turn = api->get_turn_num();
- node_id_t destination_decision = me._location;
- string stance = "Rock";
- // determine destination
- destination_decision = dm.get_current_command_location();
- // determine stance
- node_id_t stance_location = me._location;
- if (me._movement_counter-1 == me._speed){
- stance_location = destination_decision;
- }
- if (api->has_monster(stance_location)){
- Monster monster = api->get_monster(stance_location);
- stance = get_beating_stance(monster._stance);
- }
- if (my_player_num == 1)
- api->log(to_string(turn)+") goto "+to_string(destination_decision)+" with "+stance);
- api->submit_decision(destination_decision, stance);
- }
- int main() {
- while(1){
- char* buf = NULL;
- size_t size = 0;
- getline(&buf, &size, stdin);
- json data = json::parse(buf);
- if(data["type"] == "map"){
- my_player_num = data["player_id"];
- api = new Game_Api(my_player_num, data["map"]);
- } else {
- api->update(data["game_data"]);
- strategy();
- fflush(stdout);
- free(buf);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement