Skip to content

Instantly share code, notes, and snippets.

@mdakram28
Created May 26, 2014 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdakram28/006eb32194a96db35aba to your computer and use it in GitHub Desktop.
Save mdakram28/006eb32194a96db35aba to your computer and use it in GitHub Desktop.
public void playNext1(){
ArrayList<Node> temp = new ArrayList<Node>();
//System.out.println(id+" : "+sub_nodes.size());
long max = sub_nodes.get(0).pref;
for(int i=0;i<sub_nodes.size();i++)
{
if(sub_nodes.get(i).pref > max)
{
temp.clear();
temp.add(sub_nodes.get(i));
max = sub_nodes.get(i).pref;
}
else if(sub_nodes.get(i).pref == max)
{
temp.add(sub_nodes.get(i));
}
}
int choice = (int) (Math.random()*temp.size());
temp.get(choice).n++;
temp.get(choice).setAsState();
}
public void playNext2(){
ArrayList<Node> temp = new ArrayList<Node>();
//System.out.println(id+" : "+sub_nodes.size());
long min = sub_nodes.get(0).pref;
for(int i=0;i<sub_nodes.size();i++)
{
if(sub_nodes.get(i).pref < min)
{
temp.clear();
temp.add(sub_nodes.get(i));
min = sub_nodes.get(i).pref;
}
else if(sub_nodes.get(i).pref == min)
{
temp.add(sub_nodes.get(i));
}
}
int choice = (int) (Math.random()*temp.size());
temp.get(choice).n++;
temp.get(choice).setAsState();
}
public void playNextn(){
ArrayList<Node> temp = new ArrayList<Node>();
//System.out.println(id+" : "+sub_nodes.size());
int choice = 0;
long min = sub_nodes.get(0).n;
for(int i=0;i<sub_nodes.size();i++)
{
if(sub_nodes.get(i).n < min)
{
min = sub_nodes.get(i).n;
choice = i;
}
}
sub_nodes.get(choice).n++;
sub_nodes.get(choice).setAsState();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment