Project

General

Profile

« Previous | Next » 

Revision 352b3356

Added by Leszek Koltunski over 1 year ago

Read TB from file.

View differences:

src/main/java/org/distorted/objectlib/tablebases/TablebasesCreator.java
9 9

  
10 10
package org.distorted.objectlib.tablebases;
11 11

  
12
import android.content.res.Resources;
13

  
12 14
import org.distorted.library.main.QuatHelper;
13 15
import org.distorted.library.type.Static3D;
14 16
import org.distorted.library.type.Static4D;
15 17
import org.distorted.objectlib.helpers.QuatGroupGenerator;
16 18

  
19
import java.io.ByteArrayOutputStream;
20
import java.io.IOException;
21
import java.io.InputStream;
17 22
import java.util.ArrayList;
18 23

  
19 24
///////////////////////////////////////////////////////////////////////////////////////////////////
......
36 41
  private final boolean[][] mRotatable;
37 42

  
38 43
  private int[][] mQuatMult;
44
  private boolean mInitialized;
39 45

  
40 46
  private static final float[] mTmp = new float[4];
41 47

  
......
76 82
      }
77 83

  
78 84
    mRotRow = new int[mNumCubits][mNumAxis];
85
    mInitialized = true;
86
    }
87

  
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

  
90
  public TablebasesCreator(Resources res, int resource)
91
    {
92
    this();
93

  
94
    InputStream stream = res.openRawResource(resource);
95
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
96

  
97
    int nRead;
98
    byte[] tmp = new byte[16384];
99

  
100
    try
101
      {
102
      while ((nRead = stream.read(tmp, 0, tmp.length)) != -1)
103
        {
104
        buffer.write(tmp, 0, nRead);
105
        }
106

  
107
      byte[] data = buffer.toByteArray();
108
      mTablebase = new Tablebase(data);
109
      }
110
    catch(IOException ex)
111
      {
112
      mInitialized = false;
113
      }
79 114
    }
80 115

  
81 116
///////////////////////////////////////////////////////////////////////////////////////////////////
......
315 350

  
316 351
  public int[][] solution(int index)
317 352
    {
353
    if( !mInitialized ) return null;
354

  
318 355
    byte level = mTablebase.retrievePacked(index);
319 356
    ArrayList<int[]> moves = new ArrayList<>();
320 357
    int quatBasis = 0;

Also available in: Unified diff