Last active
November 14, 2019 15:01
-
-
Save adler3d/2b9f2545578f3780a28d22b2ea6fa327 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct t_world{}; // t_world | |
t_world_frag to_client=apply_fog_of_war_for(server_side_world,client); | |
struct t_world_frag{}; // t_client_side_world | |
// get_commulative_clients_info(recs,inp_frag).foreach_client(client=>get_frendly_value(client)).sum_all(); | |
// diff(smart_sizeof(t_world),smart_sizeof(t_world_frag)) | |
t_info get_commulative_clients_info(const vector<t_rec>&recs,const t_world_frag&inp_frag) | |
{ | |
t_info out; | |
//... | |
return out; | |
} | |
void foreach_correct_frame_and_state(const t_world_frag&frame,const t_world&state,vector<t_node>&out,const t_node&parent,...) | |
{ | |
auto tmp=apply_fog_of_war_for(state,client); | |
if(tmp!=frame)return; | |
out+=make_node(parent,state); | |
} | |
void grab_next_visible_states(const t_world_frag&next_frame,const t_world&state,vector<t_node>&next,const t_node&parent) | |
{ | |
t_world::foreach_next_state(state,next_state=>foreach_correct_frame_and_state(next_frame,next_state,next,parent,"apply_fog_of_war_for")); | |
} | |
number get_frendly_value(const t_client&client){ | |
client.get_input_length(); | |
client.get_enemy_list(); | |
} | |
struct t_node{ | |
t_world world; | |
optional<t_node> parent; | |
optional<t_world_out_frag> out_frag; | |
t_node get_log(){return *this;} | |
vector<number> foreach_client_map(FUNC func){ | |
return foreach_alive_client_map(func); //A | |
return foreach_deaded_client_map(func); //B | |
} | |
}; | |
struct t_log{ | |
t_node node; | |
void foreach_possible_final_log(FUNC func){ | |
vector<t_node> next; | |
next+=node; | |
vector<t_node> cur; | |
for(;!next.empty();){ | |
cur=std::move(next); | |
next.clear(); | |
cur.foreach(state=>{ | |
auto n=t_world::foreach_next_state(state.get_world(),(next_state,out_frag)=>next+=make_node(state,next_state,out_frag)); | |
if(!n)func(state.get_log()); | |
}); | |
} | |
} | |
}; | |
struct t_info{ | |
const vector<t_rec>&recs; | |
const t_world_frag&inp_frag; | |
void for_each_possible_world_log(FUNC func){ | |
auto arr=get_array_of_frames(recs,inp_frag); | |
auto frame0=arr[0]; | |
vector<t_node> first_states; | |
t_world::foreach_posible_state( | |
state=>foreach_correct_frame_and_state(frame0,state,first_states,t_node(),"apply_fog_of_war_for"); | |
); | |
vector<t_node> next=first_states; | |
vector<t_node> cur; | |
arr.foreach((frame,i)=>{ | |
if(!i)return; | |
cur=std::move(next); | |
next.clear(); | |
cur.foreach(state=>grab_next_visible_states(frame,state.get_world(),next,state)); | |
}); | |
next.foreach(node=>func(node.get_log())); | |
} | |
}; | |
t_out_frag do_nice(const vector<t_rec>&recs,const t_world_frag&inp_frag) | |
{ | |
auto info=get_commulative_clients_info(recs,inp_frag); | |
t_accum accum; | |
info.for_each_possible_world_log( | |
log=>log.foreach_possible_final_log(flog=>accum.link(flog.get_first_valid_out_frag(),flog.foreach_client_map(client=>get_frendly_value(client)).sum_all())) | |
); | |
return accum.links.get_one_with_max_value().out_frag; | |
} | |
void main(){ | |
vector<t_rec> recs; | |
for(;;) | |
{ | |
t_world_frag from_server=eval("{t_world_frag to_client=server.apply_fog_of_war_for(server_side_world,client);return to_client;}"); | |
t_out_frag to_server=do_nice(recs,from_server); | |
auto&b=qap_add_back(recs); | |
b.inp_frag=from_server; | |
b.out_frag=to_server; | |
eval("return client.out_frag;").set(to_server); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <memory> | |
#include <map> | |
using namespace std; | |
#define QapLoadFromFile(...) | |
#define QapAssert(...) | |
typedef int t_client_name; | |
typedef int t_client_move; | |
template<class TYPE> | |
struct TAutoPtr{ | |
TYPE*ptr=nullptr; | |
operator bool()const{return ptr;}; | |
TYPE*operator->(){return ptr;}; | |
}; | |
//struct t_env{}; | |
struct t_client_world{}; | |
struct t_move{ | |
struct t_rec{ | |
t_client_name id; | |
t_client_move m; | |
}; | |
vector<t_rec> arr; | |
}; | |
struct t_world{ | |
void use(t_move m){/*...*/} | |
void sim_step(){/*...*/} | |
bool valid(){return false;} | |
template<class FUNC> | |
void foreach_player(FUNC&&func){ | |
for(auto&ex:players)func(ex.id); | |
} | |
struct t_player{t_client_name id;}; | |
vector<t_player> players; | |
t_client_world get_client_world(...){return t_client_world{};}; | |
}; | |
struct i_client{virtual void solve(t_client_world&inp,t_client_move&out){}}; | |
struct t_socket{ | |
TAutoPtr<i_client> impl; | |
void solve(t_client_world&inp,t_client_move&out){impl->solve(inp,out);} | |
void random_client(){} | |
bool valid()const{return impl;} | |
}; | |
typedef t_socket t_client; | |
static bool is_valid_and_connected(t_client&c){return c.valid();} | |
struct t_test_env{ | |
t_world w; | |
vector<t_socket> socks; | |
std::map<t_client_name,t_socket> c2s; | |
void init(){ | |
QapLoadFromFile("input_world.qap",w); | |
w.foreach_player([&](t_client_name cn){ | |
c2s[cn].random_client(); | |
QapAssert(is_valid_and_connected(c2s[cn])); | |
}); | |
} | |
}; | |
int main(){ | |
t_test_env te;auto&w=te.w; | |
te.init(); | |
for(size_t iter=0;w.valid();iter++){ | |
t_move m; | |
w.foreach_player([&](t_client_name cn){ | |
t_client_move out; | |
auto inp=w.get_client_world(cn); | |
te.c2s[cn].solve(inp,out); | |
m.arr.push_back({cn,out}); | |
}); | |
w.use(m); | |
w.sim_step(); | |
} | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct t_env{ | |
struct t_move{ | |
struct t_rec{ | |
t_client_name id; | |
t_client_move m; | |
}; | |
vector<t_rec> arr; | |
}; | |
struct t_world{ | |
void use(t_move m){/*...*/} | |
void sim_step(){/*...*/} | |
}; | |
t_world w; | |
bool ok(t_world w,vector<int> way){ | |
/*...*/ | |
return true; | |
} | |
static double sqrdiff(t_world a,t_world b){/*...*/} | |
}; | |
struct t_step{ | |
t_client_world inp; | |
t_client_move out; | |
}; | |
t_client_move brain(vector<t_step> arr,t_client_world inp){ | |
/*...*/ | |
} | |
int main(){ | |
vector<t_step> mem; | |
for(;;){ | |
t_step cur; | |
t_client_world w; | |
network.recv(w); | |
{ | |
cur.inp=w; | |
rec.out=brain(mem,cur.inp); | |
mem.push_back(cur); | |
} | |
network.send(rec.out); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment