@@ -5,84 +5,87 @@ namespace MTLib.General;
55// 0 | § | ¡
66// £ | ¥ | µ
77// ¶ | ¢ | ¿
8+
89/// <summary>
910/// A grid of Symbols.
1011/// </summary>
11- public class SymbolicGrid < T > { // TODO: TEST
12- private Int32 size ;
13- private T ? [ , ] symbols ;
14- public Single Area => size * size ;
15- public Single Perimeter => 4 * size ;
16- /// <summary>
17- /// Counts all non-null Symbols.
18- /// </summary>
19- public Int32 Count {
20- get {
21- Int32 n = 0 ;
22- for ( Int32 x = 0 ; x < size ; x ++ ) {
23- for ( Int32 y = 0 ; y < size ; y ++ ) {
24- if ( symbols [ x , y ] is not null )
25- continue ;
26- n ++ ;
27- }
28- }
29- return n ;
30- }
31- }
32- public SymbolicGrid ( Int32 size , T ? fillWith ) {
33- this . size = size ;
34- this . symbols = new T [ size , size ] ;
35- this . Clear ( fillWith ) ;
36- }
37- public SymbolicGrid ( Int32 size ) {
38- this . size = size ;
39- this . symbols = new T [ size , size ] ;
40- }
41- /// <summary>
42- ///
43- /// </summary>
44- /// <returns></returns>
45- public override string ToString ( ) {
46- StringBuilder res = new ( ) ;
47- for ( Int32 x = 0 ; x < 3 ; x ++ ) {
48- for ( Int32 y = 0 ; y < 3 ; y ++ ) {
49- if ( x > 0 )
50- _ = res . Append ( ' ' ) ;
51- _ = res . Append ( this [ x , y ] ) ;
52- }
53- if ( x != 2 ) {
54- _ = res . Append ( " |" ) ;
55- }
56- }
57- return res . ToString ( ) ;
58- }
59- public T ? this [ Int32 x , Int32 y ] {
60- get => this . symbols [ x , y ] ;
61- set => this . symbols [ x , y ] = value ;
62- }
63- /// <summary>
64- /// Clears the Symbolic grid of all symbols.
65- /// </summary>
66- public void Clear ( T ? clearWith ) {
67- for ( Int32 x = 0 ; x < 3 ; x ++ ) {
68- for ( Int32 y = 0 ; y < 3 ; y ++ ) {
69- this [ x , y ] = clearWith ;
70- }
71- }
72- }
73- /// <summary>
74- /// Determines if the <paramref name="symbol"/> is in this <see cref="SymbolicGrid"/>.
75- /// </summary>
76- /// <returns><c>true</c>, if the <paramref name="symbol"/> is contained.</returns>
77- public Boolean Contains ( T ? symbol ) {
78- for ( Int32 x = 0 ; x < 3 ; x ++ ) {
79- for ( Int32 y = 0 ; y < 3 ; y ++ ) {
80- if ( this [ x , y ] ? . Equals ( symbol ) ?? false )
81- return true ;
82- if ( this [ x , y ] is null && ( symbol is null ) )
83- return true ;
84- }
85- }
86- return false ;
87- }
12+ public class SymbolicGrid < T > { // TODO: TEST ME
13+ private Int32 size ;
14+ private T ? [ , ] symbols ;
15+ public Single Area => size * size ;
16+ public Single Perimeter => 4 * size ;
17+ /// <summary>
18+ /// Counts all non-null Symbols.
19+ /// </summary>
20+ public Int32 Count {
21+ get {
22+ Int32 n = 0 ;
23+ for ( Int32 x = 0 ; x < size ; x ++ ) {
24+ for ( Int32 y = 0 ; y < size ; y ++ ) {
25+ if ( symbols [ x , y ] is not null ) { continue ; }
26+ n ++ ;
27+ }
28+ }
29+ return n ;
30+ }
31+ }
32+
33+ public SymbolicGrid ( Int32 size , T ? fillWith ) {
34+ this . size = size ;
35+ this . symbols = new T [ size , size ] ;
36+ this . Clear ( fillWith ) ;
37+ }
38+
39+ public SymbolicGrid ( Int32 size ) {
40+ this . size = size ;
41+ this . symbols = new T [ size , size ] ;
42+ }
43+
44+ /// <summary>
45+ ///
46+ /// </summary>
47+ /// <returns></returns>
48+ public override string ToString ( ) {
49+ StringBuilder res = new ( ) ;
50+ for ( Int32 x = 0 ; x < 3 ; x ++ ) {
51+ for ( Int32 y = 0 ; y < 3 ; y ++ ) {
52+ if ( x > 0 ) { _ = res . Append ( ' ' ) ; }
53+ _ = res . Append ( this [ x , y ] ) ;
54+ }
55+ if ( x != 2 ) {
56+ _ = res . Append ( " |" ) ;
57+ }
58+ }
59+ return res . ToString ( ) ;
60+ }
61+
62+ public T ? this [ Int32 x , Int32 y ] {
63+ get => this . symbols [ x , y ] ;
64+ set => this . symbols [ x , y ] = value ;
65+ }
66+
67+ /// <summary>
68+ /// Clears the Symbolic grid of all symbols.
69+ /// </summary>
70+ public void Clear ( T ? clearWith ) {
71+ for ( Int32 x = 0 ; x < 3 ; x ++ ) {
72+ for ( Int32 y = 0 ; y < 3 ; y ++ ) {
73+ this [ x , y ] = clearWith ;
74+ }
75+ }
76+ }
77+
78+ /// <summary>
79+ /// Determines if the <paramref name="symbol"/> is in this <see cref="SymbolicGrid"/>.
80+ /// </summary>
81+ /// <returns><c>true</c>, if the <paramref name="symbol"/> is contained.</returns>
82+ public Boolean Contains ( T ? symbol ) {
83+ for ( Int32 x = 0 ; x < 3 ; x ++ ) {
84+ for ( Int32 y = 0 ; y < 3 ; y ++ ) {
85+ if ( this [ x , y ] ? . Equals ( symbol ) ?? false ) { return true ; }
86+ if ( this [ x , y ] is null && ( symbol is null ) ) { return true ; }
87+ }
88+ }
89+ return false ;
90+ }
8891}
0 commit comments