Create db and db access. Add json converter for board array. Add tests for json conversion

This commit is contained in:
jheaps
2025-07-04 13:41:48 -06:00
parent ff1a131a3c
commit 7a532e52e1
18 changed files with 461 additions and 132 deletions
+8
View File
@@ -1,4 +1,8 @@
using JoshHeaps.Net.Services.Implementations;
using JoshHeaps.Net.Utilities;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
namespace JoshHeaps.Net.Models;
@@ -8,6 +12,7 @@ public class GameState
// 8x8 board of references. Null if no piece is present.
// row 0 at top -> row 7 at bottom (typical 0-based array).
[JsonConverter(typeof(ChessBoardConverter))]
public ChessPiece?[,] Board { get; set; }
// Whose turn is it?
@@ -42,7 +47,10 @@ public class GameState
public Guid BlackPlayerId { get; set; }
public bool IsVsComputer { get; set; } = false;
public int ComputerDifficulty { get; set; } = 20;
[JsonIgnore] // <-- exclude from JSON
[NotMapped] // <-- EF won't try to persist it either
public Stockfish? Computer { get; set; }
// optional: convenience
+8
View File
@@ -0,0 +1,8 @@
namespace JoshHeaps.Net.Models;
public class GameStateEntity
{
public Guid GameId { get; set; }
public string SerializedState { get; set; } = ""; // JSON
public DateTime LastMoveUtc { get; set; }
}