Skip to content

Commit 49fdbe5

Browse files
committed
v1.0 Release
1 parent 319a81f commit 49fdbe5

File tree

9 files changed

+110
-45
lines changed

9 files changed

+110
-45
lines changed

Assets/Chess/Prefab/PrefabAvatarChessAI.prefab

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Transform:
2727
m_PrefabAsset: {fileID: 0}
2828
m_GameObject: {fileID: 8446594824008165249}
2929
m_LocalRotation: {x: 0, y: 1, z: 0, w: 0}
30-
m_LocalPosition: {x: 0, y: 0, z: -0.01}
30+
m_LocalPosition: {x: 0, y: 0, z: -0.005}
3131
m_LocalScale: {x: 1, y: 1, z: 1}
3232
m_Children: []
3333
m_Father: {fileID: 8446594825741395748}
@@ -628,7 +628,7 @@ Transform:
628628
m_PrefabAsset: {fileID: 0}
629629
m_GameObject: {fileID: 8446594825045471659}
630630
m_LocalRotation: {x: 0, y: 1, z: 0, w: 0}
631-
m_LocalPosition: {x: 0, y: -0.133, z: -0.015}
631+
m_LocalPosition: {x: 0, y: -0.133, z: 0.075}
632632
m_LocalScale: {x: 1, y: 1, z: 1}
633633
m_Children: []
634634
m_Father: {fileID: 8446594824100888287}

Assets/Chess/Prefab/PrefabWorldChessAI.prefab

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ GameObject:
9090
- component: {fileID: 1568379833055391211}
9191
- component: {fileID: 1568379833055391206}
9292
m_Layer: 0
93-
m_Name: ChessAI
93+
m_Name: PrefabWorldChessAI
9494
m_TagString: Untagged
9595
m_Icon: {fileID: 0}
9696
m_NavMeshLayer: 0
@@ -378,7 +378,7 @@ Transform:
378378
m_PrefabAsset: {fileID: 0}
379379
m_GameObject: {fileID: 1568379834020412263}
380380
m_LocalRotation: {x: 0, y: 1, z: 0, w: 0}
381-
m_LocalPosition: {x: 0, y: -0.133, z: -0.015}
381+
m_LocalPosition: {x: 0, y: -0.133, z: 0.075}
382382
m_LocalScale: {x: 1, y: 1, z: 1}
383383
m_Children: []
384384
m_Father: {fileID: 1568379834696954899}
@@ -1135,7 +1135,7 @@ Transform:
11351135
m_PrefabAsset: {fileID: 0}
11361136
m_GameObject: {fileID: 1568379835057188173}
11371137
m_LocalRotation: {x: 0, y: 1, z: 0, w: 0}
1138-
m_LocalPosition: {x: 0, y: 0, z: -0.01}
1138+
m_LocalPosition: {x: 0, y: 0, z: -0.005}
11391139
m_LocalScale: {x: 1, y: 1, z: 1}
11401140
m_Children: []
11411141
m_Father: {fileID: 1568379833055391208}

Assets/Chess/Shaders/BoardGen.shader

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -228,17 +228,21 @@ Shader "ChessBot/BoardGen"
228228
curBoard[T_RIGHT] = newBoard(T_RIGHT);
229229
}
230230

231-
// // Debug Stuff
232-
// {
233-
// int2 pos = int2(floor(fmod(_Time.y * 4, 151)) * 2, floor(fmod(_Time.y * 4, 151)) * 2 + 1);
234-
// //int2 pos = int2(34, 35);
235-
// uint4 boardTop[2] = {
236-
// asuint(_BufferTex.Load(int3(pos.x, 231, 0))),
237-
// asuint(_BufferTex.Load(int3(pos.y, 231, 0)))
238-
// };
239-
// float score = eval(boardTop, turnWinUpdateLate.w);
240-
// buffer[0] = float4(score, pos.x, 231, 0);
241-
// }
231+
// Debug Stuff
232+
{
233+
// int2 pos = int2(floor(fmod(_Time.y * 4, 151)) * 2, floor(fmod(_Time.y * 4, 151)) * 2 + 1);
234+
// //int2 pos = int2(34, 35);
235+
// uint4 boardTop[2] = {
236+
// asuint(_BufferTex.Load(int3(pos.x, 145, 0))),
237+
// asuint(_BufferTex.Load(int3(pos.y, 145, 0)))
238+
// };
239+
// float score = eval(boardTop, turnWinUpdateLate.w);
240+
// buffer[0] = float4(score, pos.x, 145, 0);
241+
242+
// int pos = 360 + floor(fmod(_Time.y * 4, 151));
243+
// float4 eOut = asfloat(_BufferTex.Load(int3(pos, txEvalArea.y, 0)));
244+
// buffer[0] = eOut;
245+
}
242246

243247
// If player resigned computer wins
244248
turnWinUpdateLate.y = drawResignNewReset.y > 0.0 ?
@@ -284,10 +288,10 @@ Shader "ChessBot/BoardGen"
284288
bool lateGame = turnWinUpdateLate.w > 0.0 ? true : false;
285289

286290
// Both sides no queens
287-
buf.x = curBoard[T_LEFT][0];
288-
buf.y = curBoard[T_RIGHT][0];
289-
buf = buf & 0xff;
290-
lateGame = lateGame || ((buf.x + buf.y) > 0 ? false : true);
291+
// buf.x = curBoard[T_LEFT][0];
292+
// buf.y = curBoard[T_RIGHT][0];
293+
// buf = buf & 0xff;
294+
// lateGame = lateGame || ((buf.x + buf.y) > 0 ? false : true);
291295

292296
// One queen no pieces
293297
buf.x = curBoard[T_LEFT][0] & 0xffffff00;

Assets/Chess/Shaders/BoardOverlay.shader

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,20 @@
7171
// Hide the overlay in the touch controls since its on top of it
7272
if (unity_OrthoParams.w) discard;
7373
uint2 uv_id = floor(i.uv * 8);
74-
// float3 col = fmod(dot(uv_id, 1..xx), 2);
75-
// col = lerp(_Color2, _Color1, col.r);
74+
75+
// float4 col = float4(fmod(dot(uv_id, 1..xx), 2).xxx, 1.0);
76+
// col.rgb = lerp(_Color2, _Color1, col.r);
77+
7678
float4 col = 0.0;
7779
float2 grid_uv = fmod(i.uv * 8, 1.);
78-
7980
float frame = tex2D(_Frame, grid_uv).a;
8081

8182
uint4 board[2] = { LoadValueUint(_BufferTex, _Pixel * 2),
8283
LoadValueUint(_BufferTex, _Pixel * 2 + uint2(1, 0)) };
8384

8485
// uint4 fullBoard[4] = {
85-
// fullTests[2][0], fullTests[2][1],
86-
// fullTests[2][2], fullTests[2][3]
86+
// fullTests[3][0], fullTests[3][1],
87+
// fullTests[3][2], fullTests[3][3]
8788
// };
8889
// uint4 board[2] = { fullBoard[0], fullBoard[1] };
8990

Assets/Chess/Shaders/ChessInclude.cginc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static const uint kMask = 0x7;
3535

3636
static const float pieceVal[7] =
3737
{
38-
0, 100, 320, 330, 500, 1100, 2000000
38+
0, 70, 385, 400, 625, 1350, 2000000
3939
};
4040

4141
// Piece ID to Search Array Index
@@ -136,12 +136,12 @@ static const float pcTbl[8][8][8] =
136136

137137
// bishop
138138
-20,-10,-10,-10,-10,-10,-10,-20,
139-
-10, 0, 0, 0, 0, 0, 0,-10,
140-
-10, 0, 5, 10, 10, 5, 0,-10,
141-
-10, 5, 5, 10, 10, 5, 5,-10,
142-
-10, 0, 10, 10, 10, 10, 0,-10,
143-
-10, 10, 10, 10, 10, 10, 10,-10,
144-
-10, 5, 0, 0, 0, 0, 5,-10,
139+
-40, 0, 0, 0, 0, 0, 0,-40,
140+
-15, 0, 5, 10, 10, 5, 0,-15,
141+
-15, 5, 5, 10, 10, 5, 5,-15,
142+
-15, 0, 10, 10, 10, 10, 0,-15,
143+
-15, 10, 10, 10, 10, 10, 10,-15,
144+
-15, 5, 0, 0, 0, 0, 5,-15,
145145
-20,-20,-20,-10,-10,-20,-20,-20,
146146

147147
// rook

Assets/Chess/Shaders/Debugging.cginc

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
RWStructuredBuffer<float4> buffer : register(u1);
55

6-
static const uint4 fullTests[3][4] =
6+
static const uint4 fullTests[4][4] =
77
{
88
/*
99
0b 0100 0010 0011 0101 0110 0011 0010 0100
@@ -107,7 +107,40 @@ static const uint4 fullTests[3][4] =
107107
0b 0111 0001 0111 0010 0111 0011 0110 0100
108108
0b 0101 0101 0101 0110 0111 0111 0111 1000
109109
*/
110-
2164260982, 2231369864, 1903326052, 1431730040
110+
2164260982, 2231369864, 1903326052, 1431730040,
111+
112+
/*
113+
0b 0100 0000 0011 0000 0000 0100 0110 0000
114+
0b 0001 0001 0001 0001 0101 0001 0001 0001
115+
0b 0000 0000 0010 0011 0001 0010 0000 0000
116+
0b 0000 0000 0000 0000 0000 0000 0000 0000
117+
*/
118+
0, 2298368, 286347537, 1076888672,
119+
/*
120+
0b 0000 0000 1011 0000 1001 0000 0000 0000
121+
0b 0000 0000 1010 1001 0000 1010 0000 0000
122+
0b 1001 1001 1001 0000 0000 1001 1001 1001
123+
0b 1100 0000 1011 1101 0000 1100 1110 0000
124+
*/
125+
3233615072, 2576353689, 11078144, 11571200,
126+
/*
127+
// Queen side
128+
0b 0001 0001 0011 0011 0001 0011 0001 0100
129+
// King side
130+
0b 0001 0111 0100 0011 0011 0110 0001 0110
131+
// Queen pawns
132+
0b 0010 0001 0010 0010 0010 0011 0011 0100
133+
// King pawns
134+
0b 0100 0101 0010 0110 0010 0111 0010 1000
135+
*/
136+
288559892, 390280726, 555885364, 1160128296,
137+
/*
138+
0b 1000 0001 0110 0011 1000 0011 0111 0101
139+
0b 1000 0111 0110 0100 0110 0110 1000 0110
140+
0b 0111 0001 0111 0010 0111 0011 0111 0100
141+
0b 0110 0101 0111 0110 0111 0111 0111 1000
142+
*/
143+
2170782581, 2271504006, 1903326068, 1702262648
111144
};
112145

113146
static const uint4 pawnTests[5][4] =

Assets/Chess/VRCBot/VRCBot.shader

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@
178178
float3 lightFinal = pow(UNITY_LIGHTMODEL_AMBIENT.xyz +
179179
diffuseReflection + i.ambient_SH * 0.7, 0.8);
180180

181-
// Don't cast light on the rings
182-
col.rgb *= i.uv2.x < 0.75 ? lightFinal : 1.0;
181+
col.rgb *= lightFinal;
183182
// Make rings transparent
184183
col.a = i.uv2.x < 0.75 ? col.a : col.r;
185184

Assets/ChessAI.unity

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ GameObject:
218218
- component: {fileID: 1026906305}
219219
- component: {fileID: 1026906308}
220220
- component: {fileID: 1026906307}
221+
- component: {fileID: 1026906309}
221222
m_Layer: 0
222223
m_Name: World
223224
m_TagString: Untagged
@@ -296,16 +297,16 @@ MonoBehaviour:
296297
useAssignedLayers: 0
297298
DynamicPrefabs: []
298299
DynamicMaterials:
300+
- {fileID: 2100000, guid: c6d1ce6f86960854c90f9070c7bba93e, type: 2}
299301
- {fileID: 2100000, guid: e38f2c6e01a14b946acc2a439d516a05, type: 2}
300302
- {fileID: 2100000, guid: ce2a215fd6c38c648acea3c749a139c3, type: 2}
301303
- {fileID: 2100000, guid: 3a324910afbffb64d9a1d7c26c935acb, type: 2}
304+
- {fileID: 2100000, guid: 3cededa457b49b845aaeceb33669671b, type: 2}
302305
- {fileID: 2100000, guid: f4bc9a67e5909ed498c0ffede4dfa2c6, type: 2}
303306
- {fileID: 2100000, guid: ac43a966bf247a2418630951cf7af652, type: 2}
304-
- {fileID: 2100000, guid: c6d1ce6f86960854c90f9070c7bba93e, type: 2}
305307
- {fileID: 2100000, guid: 03738783ca21120468111847aa2ce057, type: 2}
306-
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
307-
- {fileID: 2100000, guid: 3cededa457b49b845aaeceb33669671b, type: 2}
308308
- {fileID: 2100000, guid: 98a931461714dc34c8df02ebf2ecea5f, type: 2}
309+
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
309310
LightMapsNear: []
310311
LightMapsFar: []
311312
LightMode: 0
@@ -378,6 +379,19 @@ MonoBehaviour:
378379
m_Name:
379380
m_EditorClassIdentifier:
380381
Events: []
382+
--- !u!114 &1026906309
383+
MonoBehaviour:
384+
m_ObjectHideFlags: 0
385+
m_CorrespondingSourceObject: {fileID: 0}
386+
m_PrefabInstance: {fileID: 0}
387+
m_PrefabAsset: {fileID: 0}
388+
m_GameObject: {fileID: 1026906303}
389+
m_Enabled: 1
390+
m_EditorHideFlags: 0
391+
m_Script: {fileID: 229740497, guid: 4ecd63eff847044b68db9453ce219299, type: 3}
392+
m_Name:
393+
m_EditorClassIdentifier:
394+
contentType: 1
381395
--- !u!1 &1251413839
382396
GameObject:
383397
m_ObjectHideFlags: 0
@@ -394,7 +408,7 @@ GameObject:
394408
m_Icon: {fileID: 0}
395409
m_NavMeshLayer: 0
396410
m_StaticEditorFlags: 0
397-
m_IsActive: 0
411+
m_IsActive: 1
398412
--- !u!108 &1251413840
399413
Light:
400414
m_ObjectHideFlags: 0
@@ -405,7 +419,7 @@ Light:
405419
m_Enabled: 1
406420
serializedVersion: 8
407421
m_Type: 1
408-
m_Color: {r: 1, g: 1, b: 1, a: 1}
422+
m_Color: {r: 1, g: 0.91755664, b: 0.6745283, a: 1}
409423
m_Intensity: 0.7
410424
m_Range: 10
411425
m_SpotAngle: 30
@@ -514,6 +528,11 @@ PrefabInstance:
514528
propertyPath: m_LocalEulerAnglesHint.z
515529
value: 0
516530
objectReference: {fileID: 0}
531+
- target: {fileID: 1568379834799059665, guid: 0238f3a62ae78834ca4e7cb93fce8e5e,
532+
type: 3}
533+
propertyPath: m_IsActive
534+
value: 1
535+
objectReference: {fileID: 0}
517536
m_RemovedComponents: []
518537
m_SourcePrefab: {fileID: 100100000, guid: 0238f3a62ae78834ca4e7cb93fce8e5e, type: 3}
519538
--- !u!1 &1343444030

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,19 @@ A simple AI implemented using the classic minimax algorithm except it's on a GPU
1010
* ~~Bad board evaluation function, I just copied some numbers off a site~~ (I fixed a big bug so it should work ok now)
1111
* Lots of wasted space, no dynamic memory allocation in shadurs
1212

13-
## Setup for VRChat (Sorry doesn't work in-game yet, the setups wrong)
14-
1. Import the ChessShaderWithAI.unitypackage
15-
2. Put the ChessAI prefab on your avatar
16-
3. I suggest using FinalIK or Rigidbodies to plant the chess board in world space, and the [Inventory System](https://github.com/Xiexe/VRCInventorySystem) to enable/disable the game object.
13+
## Setup for VRChat
14+
#### [VRChat layers must be setup already](https://docs.vrchat.com/docs/creating-your-first-world#step-4---setting-up-the-scene)
15+
### Avatars
16+
1. Import the ChessAi.unitypackage
17+
2. Put PrefabAvatarChessAI.prefab on your avatar
18+
3. Done. (Soft of)
19+
4. I suggest using FinalIK or Rigidbodies to plant the chess board in world space, and the [Inventory System](https://github.com/Xiexe/VRCInventorySystem) to enable/disable the game object
20+
21+
### Worlds
22+
1. Import the ChessAi.unitypackage
23+
2. Put PrefabWorldChessAI.prefab in the world
24+
3. Done.
25+
4. The difference between the avatar version and this is this one uses an object synced sphere
1726

1827
## Q & A
1928
1. What's the difference between the "New Game" and "Reset" buttons?

0 commit comments

Comments
 (0)