<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace doubleStuffed
{
    public class Board
    {
        public int[,] Spaces = new int[8, 8];
        
        /// <summary>
        /// Returns a string representation of the current state of Spaces
        /// </summary>
        /// <returns></returns>
        public string BoardString()
        {
            string output = "";
            for(int i = 0; i < 8; i++)
            {
                for(int j=0; j<8; j++)
                {
                    output += Spaces[i,j] + "  ";
                }
                output += Environment.NewLine;
            }
            return output;
        }
        
        public Board()
        {
            for(int i=0; i<8; i++)
            {
                for(int j=0; j<8; j++)
                {
                    Spaces[i,j] = 0;
                }
            }
            Spaces[3, 3] = 1;
            Spaces[4, 4] = 1;
            Spaces[3, 4] = 2;
            Spaces[4, 3] = 2;
        }

        /// <summary>
        /// Flips the token found at the designated column and row.
        /// </summary>
        /// <param name="col"></param>
        /// <param name="row"></param>
        public void FlipToken(int col, int row)
        {
            if (Spaces[col, row] == 1)
                Spaces[col, row] = 2;
            else if(Spaces[col, row] ==2)
                Spaces[col, row] = 1;
        }

        /// <summary>
        /// Clears the board of valid moves, then checks current state of the board. 
        /// </summary>
        /// <returns>If there is a valid move for the current player, return true. Else returns false.</returns>
        public bool CheckBoard(int activePlayer)
        {
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    if (Spaces[i, j] == 3)
                        Spaces[i, j] = 0;
                }
            }

            bool existsValidMove = false;
            for(int i = 0; i < 8; i++)
            {
                for(int j = 0; j < 8; j++)
                {
                    if (CheckSquare(i, j, activePlayer) == true)
                        existsValidMove = true;
                }
            }
            return existsValidMove;
        }

        //TO-DO
        /// <summary>
        /// Checks the validity of placing a token in the selected square.
        /// </summary>
        /// <returns>True if valid, false if invalid.</returns>
        public bool CheckSquare(int x, int y, int activePlayer)
        {
            return false;
        }

        //TO-DO
        /// <summary>
        /// works the same as FlipCheck(), except doesn't call flipToken() function.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="dirX"></param>
        /// <param name="dirY"></param>
        /// <returns></returns>
        /// 
        public bool CheckSquareDir(int x, int y, int dirX, int dirY, int activePlayer)
        {
            if (Spaces[x, y] == 0) //this space is empty
                return false;
            if (Spaces[x, y] == activePlayer) //this space owned by current player
                return true;
            if ((x == 0 && dirX == -1) //this space owned by opposition. next space would be out of bounds
                || (x == 7 && dirX == 1)
                || (y == 0 && dirY == -1)
                || (y == 7 && dirY == 1))
                return false;
            if (CheckSquareDir(x + dirX, y + dirY, dirX, dirY, activePlayer))
                return true;
            return false;
        }

        //TO-DO
        /// <summary>
        /// Places the token at the desired valid location and flips all tokens meeting requirements.
        /// </summary>
        public void CommitMove(int x, int y, int activePlayer)
        {

        }

        //TO-DO
        /// <summary>
        /// Recursively check the tokens in a designated direction until a token of the active player is found. Calls Board.FlipToken(x, y) on the tokens which need to be flipped.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="dirX"></param>
        /// <param name="dirY"></param>
        /// <returns></returns>
        public bool FlipCheck(int x, int y, int dirX, int dirY, int activePlayer)<commit_msg>Updated CheckBoard(): if a space is valid, replaces the "0" with a "3"<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace doubleStuffed
{
    public class Board
    {
        public int[,] Spaces = new int[8, 8];
        
        /// <summary>
        /// Returns a string representation of the current state of Spaces
        /// </summary>
        /// <returns></returns>
        public string BoardString()
        {
            string output = "";
            for(int i = 0; i < 8; i++)
            {
                for(int j=0; j<8; j++)
                {
                    output += Spaces[i,j] + "  ";
                }
                output += Environment.NewLine;
            }
            return output;
        }
        
        public Board()
        {
            for(int i=0; i<8; i++)
            {
                for(int j=0; j<8; j++)
                {
                    Spaces[i,j] = 0;
                }
            }
            Spaces[3, 3] = 1;
            Spaces[4, 4] = 1;
            Spaces[3, 4] = 2;
            Spaces[4, 3] = 2;
        }

        /// <summary>
        /// Flips the token found at the designated column and row.
        /// </summary>
        /// <param name="col"></param>
        /// <param name="row"></param>
        public void FlipToken(int col, int row)
        {
            if (Spaces[col, row] == 1)
                Spaces[col, row] = 2;
            else if(Spaces[col, row] ==2)
                Spaces[col, row] = 1;
        }

        /// <summary>
        /// Clears the board of valid moves, then checks current state of the board. 
        /// </summary>
        /// <returns>If there is a valid move for the current player, return true. Else returns false.</returns>
        public bool CheckBoard(int activePlayer)
        {
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    if (Spaces[i, j] == 3)
                        Spaces[i, j] = 0;
                }
            }

            bool existsValidMove = false;
            for(int i = 0; i < 8; i++)
            {
                for(int j = 0; j < 8; j++)
                {
                    if (Spaces[i, j] == 0 && CheckSquare(i, j, activePlayer) == true) //if the space is owned, will not call anything
                    {
                        Spaces[i, j] = 3;
                        existsValidMove = true;
                    }
                }
            }
            return existsValidMove;
        }

        //TO-DO
        /// <summary>
        /// Checks the validity of placing a token in the selected square.
        /// </summary>
        /// <returns>True if valid, false if invalid.</returns>
        public bool CheckSquare(int x, int y, int activePlayer)
        {
            //All spaces except left edge
            if (x > 0)
            {
                //All spaces except top-left corner
                if (y > 0)
                    if ((Spaces[x - 1, y - 1] != activePlayer) && CheckSquareDir(x, y, -1, -1, activePlayer)) //up-left
                        return true;

                //All spaces except left edge
                if ((Spaces[x - 1, y] != activePlayer) && CheckSquareDir(x, y, -1, 0, activePlayer)) //left
                    return true;

                //All spaces except bottom-left corner
                if (y < 7)
                    if ((Spaces[x - 1, y + 1] != activePlayer) && CheckSquareDir(x, y, -1, 1, activePlayer)) //down-left
                        return true;
            }

            //All spaces except right edge
            if (x < 7)
            {
                //All spaces except top-right corner
                if (y > 0)
                    if ((Spaces[x + 1, y - 1] != activePlayer) && CheckSquareDir(x, y, 1, -1, activePlayer)) //up-right
                        return true;

                //All spaces except right edge
                if ((Spaces[x + 1, y] != activePlayer) && CheckSquareDir(x, y, 1, 0, activePlayer)) //right
                    return true;

                //All spaces except bottom-right corner
                if (y < 7)
                    if ((Spaces[x + 1, y] != activePlayer) && CheckSquareDir(x, y, 1, 1, activePlayer)) //down-right
                        return true;
            }

            //All spaces except top edge
            if (y > 0)
                if ((Spaces[x, y - 1] != activePlayer) && CheckSquareDir(x, y, 0, -1, activePlayer)) //up
                    return true;

            //All spaces except bottom edge
            if (y < 7)
                if ((Spaces[x, y + 1] != activePlayer) && CheckSquareDir(x, y, 0, 1, activePlayer)) //down
                    return true;

            return false;
        }

        //TO-DO
        /// <summary>
        /// Checks if a space is valid from a particular direction
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="dirX"></param>
        /// <param name="dirY"></param>
        /// <returns>True if valid, false if invalid.</returns>
        /// 
        public bool CheckSquareDir(int x, int y, int dirX, int dirY, int activePlayer)
        {
            if (Spaces[x, y] == 0) //this space is empty
                return false;
            if (Spaces[x, y] == activePlayer) //this space owned by current player
                return true;
            if ((x == 0 && dirX == -1) //this space owned by opposition. next space would be out of bounds
                || (x == 7 && dirX == 1)
                || (y == 0 && dirY == -1)
                || (y == 7 && dirY == 1))
                return false;
            if (CheckSquareDir(x + dirX, y + dirY, dirX, dirY, activePlayer))
                return true;
            return false;
        }

        //TO-DO
        /// <summary>
        /// Places the token at the desired valid location and flips all tokens meeting requirements.
        /// </summary>
        public void CommitMove(int x, int y, int activePlayer)
        {
            //All spaces except left edge
                //if (y > 0): All spaces except top-left corner
                //Next Line : All spaces except left edge
                //if (y < 7): All spaces except bottom-left corner
            if (x > 0)
            {
                if (y > 0)
                    FlipCheck(x, y, -1, -1, activePlayer); //up-left

                FlipCheck(x, y, -1, 0, activePlayer); //left

                if (y < 7)
                    FlipCheck(x, y, -1, 1, activePlayer);//down-left
            }

            //All spaces except right edge
                //if (y > 0): All spaces except top-right corner
                //Next Line : All spaces except right edge
                //if (y < 7): All spaces except bottom-right corner
            if (x < 7)
            {
                if (y > 0)
                    FlipCheck(x, y, 1, -1, activePlayer); //up-right

                FlipCheck(x, y, 1, 0, activePlayer); //right

                if (y < 7)
                    FlipCheck(x, y, 1, 1, activePlayer); //down-right
            }

            //All spaces except top edge
            if (y > 0)
                FlipCheck(x, y, 0, -1, activePlayer); //up

            //All spaces except bottom edge
            if (y < 7)
                FlipCheck(x, y, 0, 1, activePlayer); //down
        }

        //TO-DO
        /// <summary>
        /// Recursively check the tokens in a designated direction until a token of the active player is found. Calls Board.FlipToken(x, y) on the tokens which need to be flipped.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="dirX"></param>
        /// <param name="dirY"></param>
        /// <returns></returns>
        public bool FlipCheck(int x, int y, int dirX, int dirY, int activePlayer)
{'fraction_non_alphanumeric': 0.12881869665789264, 'fraction_numerical': 0.012682459918640823, 'mean_word_length': 1.1680788518070206, 'pattern_counts': {'":': 0, '<': 117, '<?xml version=': 0, '>': 101, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5358146', 'n_tokens_mistral': 3663, 'n_tokens_neox': 3399, 'n_words': 1149}