Last active
March 16, 2020 09:58
-
-
Save zzzz465/8590b691dd3ebb57050e9d04259ebbd4 to your computer and use it in GitHub Desktop.
C# wrapper API for MinusKelvin/cold-clear Tetris AI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Runtime.InteropServices; | |
/* | |
write by madeline, 2020/03/15 | |
CCL-2.0 | |
*/ | |
namespace ColdClear | |
{ | |
public enum CCPiece | |
{ | |
CC_I, CC_T, CC_O, CC_S, CC_Z, CC_L, CC_J | |
} | |
public enum CCMovement | |
{ | |
CC_Left, CC_Right,CC_CW,CC_CCW,CC_Drop | |
} | |
public enum CCMovementMode | |
{ | |
CC_0G, | |
CC_20G, | |
CC_HARD_DROP_ONLY | |
} | |
[StructLayout(LayoutKind.Sequential)] | |
public struct CCMove | |
{ | |
/* Whether hold is required */ | |
public bool hold; | |
/* Expected cell coordinates of placement, (0, 0) being the bottom left */ | |
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] | |
public byte[] expected_x; | |
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] | |
public byte[] expected_y; | |
/* Number of moves in the path */ | |
public byte[] movement_count; | |
/* Movements */ | |
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] | |
public CCMovement[] movements; | |
/* Bot Info */ | |
public UInt32 nodes; | |
public UInt32 depth; | |
public UInt32 original_rank; | |
} | |
[StructLayout(LayoutKind.Sequential)] | |
public struct CCOptions | |
{ | |
public CCMovementMode mode; | |
public bool use_hold; | |
public bool speculate; | |
public UInt32 min_nodes; | |
public UInt32 max_nodes; | |
public UInt32 threads; | |
} | |
[StructLayout(LayoutKind.Sequential)] | |
public struct CCWeights | |
{ | |
public Int32 back_to_back; | |
public Int32 bumpiness; | |
public Int32 bumpiness_sq; | |
public Int32 height; | |
public Int32 top_half; | |
public Int32 top_quarter; | |
public Int32 jeopardy; | |
public Int32 cavity_cells; | |
public Int32 cavity_cells_sq; | |
public Int32 overhang_cells; | |
public Int32 overhang_cells_sq; | |
public Int32 covered_cells; | |
public Int32 covered_cells_sq; | |
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] | |
public Int32[] tslot; | |
public Int32 well_depth; | |
public Int32 max_well_depth; | |
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)] | |
public Int32[] well_column; | |
public Int32 b2b_clear; | |
public Int32 clear1; | |
public Int32 clear2; | |
public Int32 clear3; | |
public Int32 clear4; | |
public Int32 tspin1; | |
public Int32 tspin2; | |
public Int32 tspin3; | |
public Int32 mini_tspin1; | |
public Int32 mini_tspin2; | |
public Int32 perfect_clear; | |
public Int32 combo_garbage; | |
public Int32 move_time; | |
public Int32 wasted_t; | |
public bool use_bag; | |
} | |
public static class ColdClearAPI | |
{ | |
[DllImport("cold_clear")] | |
public static extern IntPtr cc_launch_async(ref CCOptions options, ref CCWeights weights); | |
[DllImport("cold_clear")] | |
public static extern IntPtr cc_launch_async(IntPtr options, IntPtr weights); | |
//[DllImport("cold_clear")] | |
//public static extern CCAsyncBot cc_launch_async(IntPtr optionsPtr, IntPtr weightsPtr); | |
[DllImport("cold_clear")] | |
public static extern void cc_destroy_async(IntPtr bot); | |
[DllImport("cold_clear")] | |
public static extern void cc_reset_async(IntPtr bot, ref bool field, bool b2b, Int32 combo); | |
[DllImport("cold_clear")] | |
public static extern void cc_add_next_piece_async(IntPtr bot, CCPiece piece); | |
[DllImport("cold_clear")] | |
public static extern void cc_request_next_move(IntPtr bot, Int32 incoming); | |
[DllImport("cold_clear")] | |
public static extern bool cc_poll_next_move(IntPtr bot, ref CCMove move); | |
[DllImport("cold_clear")] | |
public static extern bool cc_is_dead_async(IntPtr bot); | |
[DllImport("cold_clear")] | |
public static extern void cc_default_options(ref CCOptions options); | |
[DllImport("cold_clear")] | |
public static extern void cc_default_weights(ref CCWeights weights); | |
[DllImport("cold_clear")] | |
public static extern void cc_fast_weights(ref CCWeights weights); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment