source: abuse/tags/pd/abuse/src/nnetcode @ 49

Last change on this file since 49 was 49, checked in by Sam Hocevar, 11 years ago
  • Imported original public domain release, for future reference.
File size: 2.2 KB
Line 
1  if (dev_cont && dev_cont->net_store1)
2  {
3    game_object *me=focus,*other;
4    jFILE *wr;
5    if (player_number==0)
6    {
7      other=the_game->first_view->focus;
8      wr=dev_cont->net_store1;
9    } else if (player_number==1)
10    {
11      other=the_game->first_view->next->focus;
12      wr=dev_cont->net_store2;
13    }
14    double in[17];
15    make_inputs(me,other,in,nn_dist_history);
16    wr->write(in,sizeof(in));
17    double out[6];
18    if (x_suggestion>0)
19      out[0]=1;
20    else out[0]=0;
21    if (x_suggestion<0)
22      out[1]=1;
23    else out[1]=0;
24
25    if (y_suggestion>0)
26      out[2]=1;
27    else out[2]=0;
28    if (y_suggestion<0)
29      out[3]=1;
30    else out[3]=0;
31
32    out[4]=b1_suggestion;
33    out[5]=b2_suggestion;
34    wr->write(out,sizeof(out));
35  }
36
37
38else if (play_net && player_number==1)
39  {
40    game_object *me=focus,*other;
41    jFILE *wr;
42    if (player_number==0)
43    {
44      other=the_game->first_view->focus;
45      wr=dev_cont->net_store1;
46    } else if (player_number==1)
47    {
48      other=the_game->first_view->next->focus;
49      wr=dev_cont->net_store2;
50    }
51    double in[17];
52    make_inputs(me,other,in,nn_dist_history);
53    play_net->present_pattern(in);
54
55    printf("%lf %lf %lf %lf %lf %lf\n",play_net->get_output(0),play_net->get_output(1),
56           play_net->get_output(2),play_net->get_output(3),
57           play_net->get_output(4),play_net->get_output(5)
58           );
59
60    double right=play_net->get_output(0)+jrandom(10000)/(double)10000*0.1;
61    double left=play_net->get_output(1)+jrandom(10000)/(double)10000*0.1;
62    double down=play_net->get_output(2)+jrandom(10000)/(double)10000*0.1;
63    double up=play_net->get_output(3)+jrandom(10000)/(double)10000*0.1;
64
65    double b1=play_net->get_output(4)+jrandom(10000)/(double)10000*0.1;
66    double b2=play_net->get_output(5)+jrandom(10000)/(double)10000*0.1;
67
68    if (left>0.3 && left>right)
69      x_suggestion=-1;
70    else if (right>0.3)
71      x_suggestion=1;
72    else x_suggestion=0;
73
74
75    if (up>0.3 && up>down)
76      y_suggestion=-1;
77    else if (down>0.3)
78      y_suggestion=1;
79    else y_suggestion=0;
80
81
82
83    if (b1>0.3)
84      b1_suggestion=1;
85    else b1_suggestion=0;
86
87    if (b2>0.3)
88      b2_suggestion=1;
89    else b2_suggestion=0;
90
91  }
92
93 
Note: See TracBrowser for help on using the repository browser.