1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2023 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Magic Cube. //
|
5
|
// //
|
6
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
7
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
8
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9
|
|
10
|
package org.distorted.objectlib.tablebases;
|
11
|
|
12
|
import android.content.res.Resources;
|
13
|
|
14
|
import java.io.ByteArrayOutputStream;
|
15
|
import java.io.IOException;
|
16
|
import java.io.InputStream;
|
17
|
|
18
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19
|
|
20
|
public abstract class TablebasesMITM extends TablebasesAbstract
|
21
|
{
|
22
|
private PruningTable[] mTables;
|
23
|
private boolean mInitialized;
|
24
|
private int[] mLevels;
|
25
|
|
26
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
27
|
|
28
|
private void createPruningTable(Resources res, int id, int index)
|
29
|
{
|
30
|
InputStream stream = res.openRawResource(id);
|
31
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
32
|
|
33
|
int nRead;
|
34
|
byte[] tmp = new byte[16384];
|
35
|
|
36
|
try
|
37
|
{
|
38
|
while ((nRead = stream.read(tmp, 0, tmp.length)) != -1)
|
39
|
{
|
40
|
buffer.write(tmp, 0, nRead);
|
41
|
}
|
42
|
stream.close();
|
43
|
byte[] data = buffer.toByteArray();
|
44
|
buffer.close();
|
45
|
mTables[index] = new PruningTable(data);
|
46
|
mLevels[index] = mTables[index].getLevel();
|
47
|
}
|
48
|
catch(IOException ex)
|
49
|
{
|
50
|
mInitialized = false;
|
51
|
}
|
52
|
}
|
53
|
|
54
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
55
|
|
56
|
public TablebasesMITM()
|
57
|
{
|
58
|
super();
|
59
|
}
|
60
|
|
61
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
62
|
|
63
|
public TablebasesMITM(Resources res, int[] resourceIDs)
|
64
|
{
|
65
|
super();
|
66
|
|
67
|
int numOfIDs = resourceIDs.length;
|
68
|
mTables = new PruningTable[numOfIDs];
|
69
|
mLevels = new int[numOfIDs];
|
70
|
mInitialized = true;
|
71
|
|
72
|
for(int i=0; i<numOfIDs; i++) createPruningTable(res,resourceIDs[i],i);
|
73
|
}
|
74
|
|
75
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
76
|
|
77
|
public int[][] solution(int index, int[] extra)
|
78
|
{
|
79
|
return null;
|
80
|
}
|
81
|
}
|