Java List Create createActMask(ArrayList stateActions, ArrayList beliefActions)

Here you can find the source of createActMask(ArrayList stateActions, ArrayList beliefActions)

Description

create Act Mask

License

Open Source License

Declaration

public static ArrayList<Double> createActMask(ArrayList<int[]> stateActions, ArrayList<int[]> beliefActions) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.Arrays;

public class Main {
    public static ArrayList<Double> createActMask(ArrayList<int[]> stateActions, ArrayList<int[]> beliefActions) {
        ArrayList<Double> mask = new ArrayList<>(beliefActions.size());

        //this code works well and is faster if the order in which actions are listed is consistent...but this is not the case in Catan due to the discard action
        //       int idx = 0;
        //       for(int[] act : stateActions) {
        //          while(idx < beliefActions.size()) {
        //             if(Arrays.equals(act, beliefActions.get(idx))) {
        //                mask.add(1.0);
        //                idx++;
        //                break;
        //             }
        //            mask.add(0.0);
        //            idx++;
        //          }
        //       }
        //       //pad the array to the correct size
        //       while(mask.size() != beliefActions.size())
        //          mask.add(0.0);

        //this code is the safer but slightly slower option. It guarantees all actions are checked even if actions are not listed in the same order
        for (int i = 0; i < beliefActions.size(); i++) {
            mask.add(0.0);// w  w  w . java 2  s  .  com
            int[] action = beliefActions.get(i);
            for (int[] act : stateActions) {
                if (Arrays.equals(act, action)) {
                    mask.set(i, 1.0);
                    break;
                }
            }
        }

        return mask;
    }
}

Related

  1. asList(T... objs)
  2. asList(T[] array)
  3. asListBox(double[] a)
  4. asListNoNulls(T... array)
  5. create2DHorizontalIndexList( final int n)
  6. createAndInitializeList(int size, int begin)
  7. createArgumentList(List args)
  8. createArrayFromUsers(List userList)
  9. createArrayList()