shithub: moonfish

Download patch

ref: 4fec6d8c2adf20b766afa30609633df0524b9f17
parent: 7dfd3ade4698e0290379bb22064becab8428365d
author: zamfofex <zamfofex@twdb.moe>
date: Thu Oct 12 16:36:34 EDT 2023

make variable names consistent

--- a/chess.c
+++ b/chess.c
@@ -1,136 +1,136 @@
 #include "moonfish.h"
 
-static struct moonfish_move *moonfish_create_move(struct moonfish_chess *ctx, struct moonfish_move **moves, unsigned char from, unsigned char to)
+static struct moonfish_move *moonfish_create_move(struct moonfish_chess *chess, struct moonfish_move **moves, unsigned char from, unsigned char to)
 {
 	(*moves)->from = from;
 	(*moves)->to = to;
-	(*moves)->piece = ctx->board[from];
-	(*moves)->promotion = ctx->board[from];
-	(*moves)->captured = ctx->board[to];
-	(*moves)->castle = ctx->castle;
+	(*moves)->piece = chess->board[from];
+	(*moves)->promotion = chess->board[from];
+	(*moves)->captured = chess->board[to];
+	(*moves)->castle = chess->castle;
 	return (*moves)++;
 }
 
-static char moonfish_delta(struct moonfish_chess *ctx, struct moonfish_move **moves, unsigned char from, unsigned char *to, signed char delta)
+static char moonfish_delta(struct moonfish_chess *chess, struct moonfish_move **moves, unsigned char from, unsigned char *to, signed char delta)
 {
 	*to += delta;
-	if (ctx->board[*to] <= moonfish_our_king) return 0;
-	moonfish_create_move(ctx, moves, from, *to);
-	if (ctx->board[*to] != moonfish_empty) return 0;
+	if (chess->board[*to] <= moonfish_our_king) return 0;
+	moonfish_create_move(chess, moves, from, *to);
+	if (chess->board[*to] != moonfish_empty) return 0;
 	return 1;
 }
 
-static void moonfish_slide(struct moonfish_chess *ctx, struct moonfish_move **moves, unsigned char from, signed char delta)
+static void moonfish_slide(struct moonfish_chess *chess, struct moonfish_move **moves, unsigned char from, signed char delta)
 {
 	unsigned char to;
 	to = from;
-	while (moonfish_delta(ctx, moves, from, &to, delta)) { }
+	while (moonfish_delta(chess, moves, from, &to, delta)) { }
 }
 
-static void moonfish_jump(struct moonfish_chess *ctx, struct moonfish_move **moves, unsigned char from, signed char delta)
+static void moonfish_jump(struct moonfish_chess *chess, struct moonfish_move **moves, unsigned char from, signed char delta)
 {
-	moonfish_delta(ctx, moves, from, &from, delta);
+	moonfish_delta(chess, moves, from, &from, delta);
 }
 
-static void moonfish_move_knight(struct moonfish_chess *ctx, struct moonfish_move **moves, unsigned char from)
+static void moonfish_move_knight(struct moonfish_chess *chess, struct moonfish_move **moves, unsigned char from)
 {
-	moonfish_jump(ctx, moves, from, 21);
-	moonfish_jump(ctx, moves, from, 19);
-	moonfish_jump(ctx, moves, from, -19);
-	moonfish_jump(ctx, moves, from, -21);
-	moonfish_jump(ctx, moves, from, 12);
-	moonfish_jump(ctx, moves, from, 8);
-	moonfish_jump(ctx, moves, from, -8);
-	moonfish_jump(ctx, moves, from, -12);
+	moonfish_jump(chess, moves, from, 21);
+	moonfish_jump(chess, moves, from, 19);
+	moonfish_jump(chess, moves, from, -19);
+	moonfish_jump(chess, moves, from, -21);
+	moonfish_jump(chess, moves, from, 12);
+	moonfish_jump(chess, moves, from, 8);
+	moonfish_jump(chess, moves, from, -8);
+	moonfish_jump(chess, moves, from, -12);
 }
 
-static void moonfish_move_bishop(struct moonfish_chess *ctx, struct moonfish_move **moves, unsigned char from)
+static void moonfish_move_bishop(struct moonfish_chess *chess, struct moonfish_move **moves, unsigned char from)
 {
-	moonfish_slide(ctx, moves, from, 11);
-	moonfish_slide(ctx, moves, from, 9);
-	moonfish_slide(ctx, moves, from, -9);
-	moonfish_slide(ctx, moves, from, -11);
+	moonfish_slide(chess, moves, from, 11);
+	moonfish_slide(chess, moves, from, 9);
+	moonfish_slide(chess, moves, from, -9);
+	moonfish_slide(chess, moves, from, -11);
 }
 
-static void moonfish_move_rook(struct moonfish_chess *ctx, struct moonfish_move **moves, unsigned char from)
+static void moonfish_move_rook(struct moonfish_chess *chess, struct moonfish_move **moves, unsigned char from)
 {
-	moonfish_slide(ctx, moves, from, 10);
-	moonfish_slide(ctx, moves, from, -10);
-	moonfish_slide(ctx, moves, from, 1);
-	moonfish_slide(ctx, moves, from, -1);
+	moonfish_slide(chess, moves, from, 10);
+	moonfish_slide(chess, moves, from, -10);
+	moonfish_slide(chess, moves, from, 1);
+	moonfish_slide(chess, moves, from, -1);
 }
 
-static void moonfish_move_queen(struct moonfish_chess *ctx, struct moonfish_move **moves, unsigned char from)
+static void moonfish_move_queen(struct moonfish_chess *chess, struct moonfish_move **moves, unsigned char from)
 {
-	moonfish_move_rook(ctx, moves, from);
-	moonfish_move_bishop(ctx, moves, from);
+	moonfish_move_rook(chess, moves, from);
+	moonfish_move_bishop(chess, moves, from);
 }
 
-static char moonfish_attacked(struct moonfish_chess *ctx, unsigned char from, unsigned char to)
+static char moonfish_attacked(struct moonfish_chess *chess, unsigned char from, unsigned char to)
 {
 	int check;
-	ctx->board[from] = moonfish_empty;
-	ctx->board[to] = moonfish_our_king;
-	check = moonfish_check(ctx);
-	ctx->board[from] = moonfish_our_king;
-	ctx->board[to] = moonfish_empty;
+	chess->board[from] = moonfish_empty;
+	chess->board[to] = moonfish_our_king;
+	check = moonfish_check(chess);
+	chess->board[from] = moonfish_our_king;
+	chess->board[to] = moonfish_empty;
 	return check;
 }
 
-static void moonfish_castle_low(struct moonfish_chess *ctx, struct moonfish_move **moves, unsigned char from)
+static void moonfish_castle_low(struct moonfish_chess *chess, struct moonfish_move **moves, unsigned char from)
 {
 	unsigned char to;
 	
 	for (to = 22 ; to != from ; to++)
-		if (ctx->board[to] != moonfish_empty)
+		if (chess->board[to] != moonfish_empty)
 			return;
 	
-	if (moonfish_check(ctx)) return;
-	if (moonfish_attacked(ctx, from, from - 1)) return;
-	if (moonfish_attacked(ctx, from, from - 2)) return;
+	if (moonfish_check(chess)) return;
+	if (moonfish_attacked(chess, from, from - 1)) return;
+	if (moonfish_attacked(chess, from, from - 2)) return;
 	
-	moonfish_create_move(ctx, moves, from, from - 2);
+	moonfish_create_move(chess, moves, from, from - 2);
 }
 
-static void moonfish_castle_high(struct moonfish_chess *ctx, struct moonfish_move **moves, unsigned char from)
+static void moonfish_castle_high(struct moonfish_chess *chess, struct moonfish_move **moves, unsigned char from)
 {
 	unsigned char to;
 	
 	for (to = 27 ; to != from ; to--)
-		if (ctx->board[to] != moonfish_empty)
+		if (chess->board[to] != moonfish_empty)
 			return;
 	
-	if (moonfish_check(ctx)) return;
-	if (moonfish_attacked(ctx, from, from + 1)) return;
-	if (moonfish_attacked(ctx, from, from + 2)) return;
+	if (moonfish_check(chess)) return;
+	if (moonfish_attacked(chess, from, from + 1)) return;
+	if (moonfish_attacked(chess, from, from + 2)) return;
 	
-	moonfish_create_move(ctx, moves, from, from + 2);
+	moonfish_create_move(chess, moves, from, from + 2);
 }
 
-static void moonfish_move_king(struct moonfish_chess *ctx, struct moonfish_move **moves, unsigned char from)
+static void moonfish_move_king(struct moonfish_chess *chess, struct moonfish_move **moves, unsigned char from)
 {
-	moonfish_jump(ctx, moves, from, 1 + 10);
-	moonfish_jump(ctx, moves, from, -1 + 10);
-	moonfish_jump(ctx, moves, from, 1 - 10);
-	moonfish_jump(ctx, moves, from, -1 - 10);
-	moonfish_jump(ctx, moves, from, 10);
-	moonfish_jump(ctx, moves, from, -10);
-	moonfish_jump(ctx, moves, from, 1);
-	moonfish_jump(ctx, moves, from, -1);
+	moonfish_jump(chess, moves, from, 1 + 10);
+	moonfish_jump(chess, moves, from, -1 + 10);
+	moonfish_jump(chess, moves, from, 1 - 10);
+	moonfish_jump(chess, moves, from, -1 - 10);
+	moonfish_jump(chess, moves, from, 10);
+	moonfish_jump(chess, moves, from, -10);
+	moonfish_jump(chess, moves, from, 1);
+	moonfish_jump(chess, moves, from, -1);
 	
-	if (!ctx->white && from == 24)
+	if (!chess->white && from == 24)
 	{
-		if (ctx->castle.black_oo) moonfish_castle_low(ctx, moves, from);
-		if (ctx->castle.black_ooo) moonfish_castle_high(ctx, moves, from);
+		if (chess->castle.black_oo) moonfish_castle_low(chess, moves, from);
+		if (chess->castle.black_ooo) moonfish_castle_high(chess, moves, from);
 	}
-	if (ctx->white && from == 25)
+	if (chess->white && from == 25)
 	{
-		if (ctx->castle.white_oo) moonfish_castle_high(ctx, moves, from);
-		if (ctx->castle.white_ooo) moonfish_castle_low(ctx, moves, from);
+		if (chess->castle.white_oo) moonfish_castle_high(chess, moves, from);
+		if (chess->castle.white_ooo) moonfish_castle_low(chess, moves, from);
 	}
 }
 
-static void moonfish_move_pawn(struct moonfish_chess *ctx, struct moonfish_move **moves, unsigned char from)
+static void moonfish_move_pawn(struct moonfish_chess *chess, struct moonfish_move **moves, unsigned char from)
 {
 	struct moonfish_move *move;
 	unsigned char promotion;
@@ -138,58 +138,58 @@
 	promotion = moonfish_our_pawn;
 	if (from > 80) promotion = moonfish_our_queen;
 	
-	if (ctx->board[from + 10] == moonfish_empty)
+	if (chess->board[from + 10] == moonfish_empty)
 	{
-		move = moonfish_create_move(ctx, moves, from, from + 10);
+		move = moonfish_create_move(chess, moves, from, from + 10);
 		move->promotion = promotion;
 				
 		if (from < 40)
 		{
-			if (ctx->board[from + 20] == moonfish_empty)
+			if (chess->board[from + 20] == moonfish_empty)
 			{
-				move = moonfish_create_move(ctx, moves, from, from + 20);
+				move = moonfish_create_move(chess, moves, from, from + 20);
 				move->promotion = promotion;
 			}
 		}
 	}
 	
-	if (ctx->board[from + 9] >= moonfish_their_pawn)
-	if (ctx->board[from + 9] != moonfish_empty)
+	if (chess->board[from + 9] >= moonfish_their_pawn)
+	if (chess->board[from + 9] != moonfish_empty)
 	{
-		move = moonfish_create_move(ctx, moves, from, from + 9);
+		move = moonfish_create_move(chess, moves, from, from + 9);
 		move->promotion = promotion;
 	}
 	
-	if (ctx->board[from + 11] >= moonfish_their_pawn)
-	if (ctx->board[from + 11] != moonfish_empty)
+	if (chess->board[from + 11] >= moonfish_their_pawn)
+	if (chess->board[from + 11] != moonfish_empty)
 	{
-		move = moonfish_create_move(ctx, moves, from, from + 11);
+		move = moonfish_create_move(chess, moves, from, from + 11);
 		move->promotion = promotion;
 	}
 }
 
-void moonfish_moves(struct moonfish_chess *ctx, struct moonfish_move *moves, unsigned char from)
+void moonfish_moves(struct moonfish_chess *chess, struct moonfish_move *moves, unsigned char from)
 {
 	unsigned char piece;
-	piece = ctx->board[from];
-	if (piece == moonfish_our_pawn) moonfish_move_pawn(ctx, &moves, from);
-	if (piece == moonfish_our_knight) moonfish_move_knight(ctx, &moves, from);
-	if (piece == moonfish_our_bishop) moonfish_move_bishop(ctx, &moves, from);
-	if (piece == moonfish_our_rook) moonfish_move_rook(ctx, &moves, from);
-	if (piece == moonfish_our_queen) moonfish_move_queen(ctx, &moves, from);
-	if (piece == moonfish_our_king) moonfish_move_king(ctx, &moves, from);
+	piece = chess->board[from];
+	if (piece == moonfish_our_pawn) moonfish_move_pawn(chess, &moves, from);
+	if (piece == moonfish_our_knight) moonfish_move_knight(chess, &moves, from);
+	if (piece == moonfish_our_bishop) moonfish_move_bishop(chess, &moves, from);
+	if (piece == moonfish_our_rook) moonfish_move_rook(chess, &moves, from);
+	if (piece == moonfish_our_queen) moonfish_move_queen(chess, &moves, from);
+	if (piece == moonfish_our_king) moonfish_move_king(chess, &moves, from);
 	moves->piece = moonfish_outside;
 }
 
-static void moonfish_swap(struct moonfish_chess *ctx, int i, int j)
+static void moonfish_swap(struct moonfish_chess *chess, int i, int j)
 {
 	unsigned char piece;
-	piece = ctx->board[i];
-	ctx->board[i] = ctx->board[j];
-	ctx->board[j] = piece;
+	piece = chess->board[i];
+	chess->board[i] = chess->board[j];
+	chess->board[j] = piece;
 }
 
-static void moonfish_flip_horizontally(struct moonfish_chess *ctx)
+static void moonfish_flip_horizontally(struct moonfish_chess *chess)
 {
 	int x, y;
 	
@@ -196,7 +196,7 @@
 	for (y = 0 ; y < 8 ; y++)
 	for (x = 0 ; x < 4 ; x++)
 	{
-		moonfish_swap(ctx,
+		moonfish_swap(chess,
 			(x + 1) + (y + 2) * 10,
 			(8 - x) + (y + 2) * 10
 		);
@@ -203,7 +203,7 @@
 	}
 }
 
-static void moonfish_flip_vertically(struct moonfish_chess *ctx)
+static void moonfish_flip_vertically(struct moonfish_chess *chess)
 {
 	int x, y;
 	
@@ -210,7 +210,7 @@
 	for (y = 0 ; y < 4 ; y++)
 	for (x = 0 ; x < 8 ; x++)
 	{
-		moonfish_swap(ctx,
+		moonfish_swap(chess,
 			(x + 1) + (y + 2) * 10,
 			(x + 1) + (9 - y) * 10
 		);
@@ -217,29 +217,29 @@
 	}
 }
 
-static void moonfish_rotate(struct moonfish_chess *ctx)
+static void moonfish_rotate(struct moonfish_chess *chess)
 {
 	int x, y;
 	
-	moonfish_flip_horizontally(ctx);
-	moonfish_flip_vertically(ctx);
+	moonfish_flip_horizontally(chess);
+	moonfish_flip_vertically(chess);
 	
-	ctx->white ^= 1;
+	chess->white ^= 1;
 	
 	for (y = 0 ; y < 8 ; y++)
 	for (x = 0 ; x < 8 ; x++)
 	{
-		if (ctx->board[(x + 1) + (y + 2) * 10] != moonfish_empty)
-			ctx->board[(x + 1) + (y + 2) * 10] ^= 0x30;
+		if (chess->board[(x + 1) + (y + 2) * 10] != moonfish_empty)
+			chess->board[(x + 1) + (y + 2) * 10] ^= 0x30;
 	}
 }
 
-void moonfish_play(struct moonfish_chess *ctx, struct moonfish_move *move)
+void moonfish_play(struct moonfish_chess *chess, struct moonfish_move *move)
 {
 	int x0, x1;
 	
-	ctx->board[move->from] = moonfish_empty;
-	ctx->board[move->to] = move->promotion;
+	chess->board[move->from] = moonfish_empty;
+	chess->board[move->to] = move->promotion;
 	
 	if (move->piece == moonfish_our_king)
 	{
@@ -248,17 +248,17 @@
 		if (move->from == 24 && move->to == 26) x0 = 8, x1 = 5;
 		if (move->from == 25 && move->to == 27) x0 = 8, x1 = 6;
 		if (move->from == 25 && move->to == 23) x0 = 1, x1 = 4;
-		if (x0) ctx->board[x0 + 20] = moonfish_empty, ctx->board[x1 + 20] = moonfish_our_rook;
+		if (x0) chess->board[x0 + 20] = moonfish_empty, chess->board[x1 + 20] = moonfish_our_rook;
 		
-		if (ctx->white)
+		if (chess->white)
 		{
-			ctx->castle.white_oo = 0;
-			ctx->castle.white_ooo = 0;
+			chess->castle.white_oo = 0;
+			chess->castle.white_ooo = 0;
 		}
 		else
 		{
-			ctx->castle.black_oo = 0;
-			ctx->castle.black_ooo = 0;
+			chess->castle.black_oo = 0;
+			chess->castle.black_ooo = 0;
 		}
 	}
 	
@@ -266,13 +266,13 @@
 	{
 		if (move->from == 28)
 		{
-			if (ctx->white) ctx->castle.white_ooo = 0;
-			else ctx->castle.black_oo = 0;
+			if (chess->white) chess->castle.white_ooo = 0;
+			else chess->castle.black_oo = 0;
 		}
 		if (move->from == 21)
 		{
-			if (ctx->white) ctx->castle.white_oo = 0;
-			else ctx->castle.black_ooo = 0;
+			if (chess->white) chess->castle.white_oo = 0;
+			else chess->castle.black_ooo = 0;
 		}
 	}
 	
@@ -280,28 +280,28 @@
 	{
 		if (move->to == 98)
 		{
-			if (ctx->white) ctx->castle.black_oo = 0;
-			else ctx->castle.white_ooo = 0;
+			if (chess->white) chess->castle.black_oo = 0;
+			else chess->castle.white_ooo = 0;
 		}
 		if (move->to == 91)
 		{
-			if (ctx->white) ctx->castle.black_ooo = 0;
-			else ctx->castle.white_oo = 0;
+			if (chess->white) chess->castle.black_ooo = 0;
+			else chess->castle.white_oo = 0;
 		}
 	}
 	
-	moonfish_rotate(ctx);
+	moonfish_rotate(chess);
 }
 
-void moonfish_unplay(struct moonfish_chess *ctx, struct moonfish_move *move)
+void moonfish_unplay(struct moonfish_chess *chess, struct moonfish_move *move)
 {
 	int x0, x1;
 	
-	moonfish_rotate(ctx);
+	moonfish_rotate(chess);
 	
-	ctx->board[move->from] = move->piece;
-	ctx->board[move->to] = move->captured;
-	ctx->castle = move->castle;
+	chess->board[move->from] = move->piece;
+	chess->board[move->to] = move->captured;
+	chess->castle = move->castle;
 	
 	if (move->piece == moonfish_our_king)
 	{
@@ -310,22 +310,22 @@
 		if (move->from == 24 && move->to == 26) x0 = 8, x1 = 5;
 		if (move->from == 25 && move->to == 27) x0 = 8, x1 = 6;
 		if (move->from == 25 && move->to == 23) x0 = 1, x1 = 4;
-		if (x0) ctx->board[x1 + 20] = moonfish_empty, ctx->board[x0 + 20] = moonfish_our_rook;
+		if (x0) chess->board[x1 + 20] = moonfish_empty, chess->board[x0 + 20] = moonfish_our_rook;
 	}
 }
 
-void moonfish_chess(struct moonfish_chess *ctx)
+void moonfish_chess(struct moonfish_chess *chess)
 {
 	int x, y;
 	
 	for (y = 0 ; y < 12 ; y++)
 	for (x = 0 ; x < 10 ; x++)
-		ctx->board[x + y * 10] = moonfish_outside;
+		chess->board[x + y * 10] = moonfish_outside;
 	
-	moonfish_fen(ctx, "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq");
+	moonfish_fen(chess, "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq");
 }
 
-void moonfish_play_uci(struct moonfish_chess *ctx, char *name)
+void moonfish_play_uci(struct moonfish_chess *chess, char *name)
 {
 	struct moonfish_move move;
 	int x, y;
@@ -333,7 +333,7 @@
 	x = name[0] - 'a';
 	y = name[1] - '1';
 	
-	if (!ctx->white)
+	if (!chess->white)
 	{
 		x = 7 - x;
 		y = 7 - y;
@@ -344,7 +344,7 @@
 	x = name[2] - 'a';
 	y = name[3] - '1';
 	
-	if (!ctx->white)
+	if (!chess->white)
 	{
 		x = 7 - x;
 		y = 7 - y;
@@ -352,14 +352,14 @@
 	
 	move.to = (x + 1) + (y + 2) * 10;
 	
-	move.piece = ctx->board[move.from];
-	move.captured = ctx->board[move.to];
+	move.piece = chess->board[move.from];
+	move.captured = chess->board[move.to];
 	move.promotion = move.piece;
 	
 	if (move.piece == moonfish_our_pawn)
 	if ((move.to - move.from) % 10)
 	if (move.captured == moonfish_empty)
-		ctx->board[move.to - 10] = moonfish_empty;
+		chess->board[move.to - 10] = moonfish_empty;
 	
 	if (name[4] == 'q') move.promotion = moonfish_our_queen;
 	if (name[4] == 'r') move.promotion = moonfish_our_rook;
@@ -366,7 +366,7 @@
 	if (name[4] == 'b') move.promotion = moonfish_our_bishop;
 	if (name[4] == 'n') move.promotion = moonfish_our_knight;
 	
-	moonfish_play(ctx, &move);
+	moonfish_play(chess, &move);
 }
 
 void moonfish_to_uci(char *name, struct moonfish_move *move, int white)
@@ -408,7 +408,7 @@
 	}
 }
 
-void moonfish_fen(struct moonfish_chess *ctx, char *fen)
+void moonfish_fen(struct moonfish_chess *chess, char *fen)
 {
 	int x, y;
 	unsigned char type, color;
@@ -416,16 +416,16 @@
 	
 	for (y = 0 ; y < 8 ; y++)
 	for (x = 0 ; x < 8 ; x++)
-		ctx->board[(x + 1) + (y + 2) * 10] = moonfish_empty;
+		chess->board[(x + 1) + (y + 2) * 10] = moonfish_empty;
 	
 	x = 0;
 	y = 0;
 	
-	ctx->white = 1;
-	ctx->castle.white_oo = 0;
-	ctx->castle.white_ooo = 0;
-	ctx->castle.black_oo = 0;
-	ctx->castle.black_ooo = 0;
+	chess->white = 1;
+	chess->castle.white_oo = 0;
+	chess->castle.white_ooo = 0;
+	chess->castle.black_oo = 0;
+	chess->castle.black_ooo = 0;
 	
 	for (;;)
 	{
@@ -461,12 +461,12 @@
 		if (ch == 'q') type = 5;
 		if (ch == 'k') type = 6;
 		
-		ctx->board[(x + 1) + (9 - y) * 10] = type | color;
+		chess->board[(x + 1) + (9 - y) * 10] = type | color;
 		
 		x++;
 	}
 	
-	if (*fen++ == 'b') moonfish_rotate(ctx);
+	if (*fen++ == 'b') moonfish_rotate(chess);
 	if (*fen++ != ' ') return;
 	
 	for (;;)
@@ -474,14 +474,14 @@
 		ch = *fen++;
 		if (ch == 0) return;
 		if (ch == ' ') break;
-		if (ch == 'K') ctx->castle.white_oo = 1;
-		if (ch == 'Q') ctx->castle.white_ooo = 1;
-		if (ch == 'k') ctx->castle.black_oo = 1;
-		if (ch == 'q') ctx->castle.black_ooo = 1;
+		if (ch == 'K') chess->castle.white_oo = 1;
+		if (ch == 'Q') chess->castle.white_ooo = 1;
+		if (ch == 'k') chess->castle.black_oo = 1;
+		if (ch == 'q') chess->castle.black_ooo = 1;
 	}
 }
 
-int moonfish_validate(struct moonfish_chess *ctx)
+int moonfish_validate(struct moonfish_chess *chess)
 {
 	int x, y;
 	struct moonfish_move moves[32];
@@ -490,7 +490,7 @@
 	for (y = 0 ; y < 8 ; y++)
 	for (x = 0 ; x < 8 ; x++)
 	{
-		moonfish_moves(ctx, moves, (x + 1) + (y + 2) * 10);
+		moonfish_moves(chess, moves, (x + 1) + (y + 2) * 10);
 		for (move = moves ; move->piece != moonfish_outside ; move++)
 			if (move->captured == moonfish_their_king)
 				return 0;
@@ -499,23 +499,23 @@
 	return 1;
 }
 
-int moonfish_check(struct moonfish_chess *ctx)
+int moonfish_check(struct moonfish_chess *chess)
 {
 	int valid;
 	struct moonfish_castle castle;
 	
-	castle = ctx->castle;
+	castle = chess->castle;
 	
-	ctx->castle.white_oo = 0;
-	ctx->castle.white_ooo = 0;
-	ctx->castle.black_oo = 0;
-	ctx->castle.black_ooo = 0;
+	chess->castle.white_oo = 0;
+	chess->castle.white_ooo = 0;
+	chess->castle.black_oo = 0;
+	chess->castle.black_ooo = 0;
 	
-	moonfish_rotate(ctx);
-	valid = moonfish_validate(ctx);
-	moonfish_rotate(ctx);
+	moonfish_rotate(chess);
+	valid = moonfish_validate(chess);
+	moonfish_rotate(chess);
 	
-	ctx->castle = castle;
+	chess->castle = castle;
 	
 	return valid ^ 1;
 }
--- a/moonfish.h
+++ b/moonfish.h
@@ -62,25 +62,25 @@
 	struct moonfish_castle castle;
 };
 
-int moonfish_nnue(struct moonfish_nnue *ctx, FILE *file);
+int moonfish_nnue(struct moonfish_nnue *nnue, FILE *file);
 
-void moonfish_chess(struct moonfish_chess *ctx);
-void moonfish_fen(struct moonfish_chess *ctx, char *fen);
+void moonfish_chess(struct moonfish_chess *chess);
+void moonfish_fen(struct moonfish_chess *chess, char *fen);
 
-void moonfish_moves(struct moonfish_chess *ctx, struct moonfish_move *moves, unsigned char from);
+void moonfish_moves(struct moonfish_chess *chess, struct moonfish_move *moves, unsigned char from);
 
-void moonfish_play(struct moonfish_chess *ctx, struct moonfish_move *move);
-void moonfish_unplay(struct moonfish_chess *ctx, struct moonfish_move *move);
+void moonfish_play(struct moonfish_chess *chess, struct moonfish_move *move);
+void moonfish_unplay(struct moonfish_chess *chess, struct moonfish_move *move);
 
 int moonfish_tanh(int value);
 
 int moonfish_best_move(struct moonfish *ctx, struct moonfish_move *move);
 
-void moonfish_play_uci(struct moonfish_chess *ctx, char *name);
+void moonfish_play_uci(struct moonfish_chess *chess, char *name);
 void moonfish_to_uci(char *name, struct moonfish_move *move, int white);
 
-int moonfish_validate(struct moonfish_chess *ctx);
-int moonfish_check(struct moonfish_chess *ctx);
+int moonfish_validate(struct moonfish_chess *chess);
+int moonfish_check(struct moonfish_chess *chess);
 
 extern char *moonfish_network;
 
--- a/nnue.c
+++ b/nnue.c
@@ -15,7 +15,7 @@
 	return 0;
 }
 
-static int moonfish_read_nnue(struct moonfish_nnue *ctx, FILE *file)
+static int moonfish_read_nnue(struct moonfish_nnue *nnue, FILE *file)
 {
 	int ch;
 	unsigned int i, j;
@@ -25,23 +25,23 @@
 	if (fgetc(file) != 'L') return 1;
 	if (fgetc(file) != 'u') return 1;
 	if (fgetc(file) != 'n') return 1;
-	if (moonfish_read_array(ctx->pst0, sizeof ctx->pst0, file)) return 1;
-	if (moonfish_read_array(ctx->pst1, sizeof ctx->pst1, file)) return 1;
-	if (moonfish_read_array(ctx->pst3, sizeof ctx->pst3, file)) return 1;
-	if (moonfish_read_array(ctx->layer1, sizeof ctx->layer1, file)) return 1;
-	if (moonfish_read_array(ctx->layer2, sizeof ctx->layer2, file)) return 1;
+	if (moonfish_read_array(nnue->pst0, sizeof nnue->pst0, file)) return 1;
+	if (moonfish_read_array(nnue->pst1, sizeof nnue->pst1, file)) return 1;
+	if (moonfish_read_array(nnue->pst3, sizeof nnue->pst3, file)) return 1;
+	if (moonfish_read_array(nnue->layer1, sizeof nnue->layer1, file)) return 1;
+	if (moonfish_read_array(nnue->layer2, sizeof nnue->layer2, file)) return 1;
 	
 	for (i = 0 ; i < 4 ; i++)
 	for (j = 0 ; j < 6 * 8 ; j++)
 	{
-		v = ctx->pst0[i * 6 * 8 + j];
-		ctx->pst0[i * 6 * 8 + j] = ctx->pst0[(7 - i) * 6 * 8 + j];
-		ctx->pst0[(7 - i) * 6 * 8 + j] = v;
+		v = nnue->pst0[i * 6 * 8 + j];
+		nnue->pst0[i * 6 * 8 + j] = nnue->pst0[(7 - i) * 6 * 8 + j];
+		nnue->pst0[(7 - i) * 6 * 8 + j] = v;
 	}
 	
 	ch = fgetc(file);
 	if (ch == EOF) return 1;
-	ctx->scale = ch;
+	nnue->scale = ch;
 	
 	if (fgetc(file) != EOF) return 1;
 	
@@ -48,11 +48,11 @@
 	return 0;
 }
 
-int moonfish_nnue(struct moonfish_nnue *ctx, FILE *file)
+int moonfish_nnue(struct moonfish_nnue *nnue, FILE *file)
 {
 	int p, s, d, o, c, value;
 	
-	if (moonfish_read_nnue(ctx, file)) return 1;
+	if (moonfish_read_nnue(nnue, file)) return 1;
 	
 	for (p = 0 ; p < 6 ; p++)
 	for (s = 0 ; s < 64 ; s++)
@@ -60,8 +60,8 @@
 	{
 		value = 0;
 		for (d = 0 ; d < 6 ; d++)
-			value += ctx->pst0[s * 6 + d] * ctx->pst1[o * 6 * 6 + d * 6 + p];
-		ctx->values0[p][s][o] = value / 127;
+			value += nnue->pst0[s * 6 + d] * nnue->pst1[o * 6 * 6 + d * 6 + p];
+		nnue->values0[p][s][o] = value / 127;
 	}
 	
 	for (c = 0 ; c < 2 ; c++)
@@ -71,8 +71,8 @@
 	{
 		value = 0;
 		for (d = 0 ; d < 10 ; d++)
-			value += ctx->values0[p][s][d] * ctx->pst3[o * 10 * 2 + d * 2 + c];
-		ctx->values[c][p][s][o] = value / 127;
+			value += nnue->values0[p][s][d] * nnue->pst3[o * 10 * 2 + d * 2 + c];
+		nnue->values[c][p][s][o] = value / 127;
 	}
 	
 	return 0;
--