<commit_before>//|||||||||||||||||||||||||||||||||||||||||||||||

#include "Chess.h"

#include <OgreLight.h>
#include <OgreWindowEventUtilities.h>
#include "OgreText.h"

/* since pipes are unidirectional, we need two pipes.
 one for data to flow from parent's stdout to child's
 stdin and the other for child's stdout to flow to
 parent's stdin */

#define NUM_PIPES          2

#define PARENT_WRITE_PIPE  0
#define PARENT_READ_PIPE   1

int pipes[NUM_PIPES][2];

/* always in a pipe[], pipe[0] is for read and
 pipe[1] is for write */
#define READ_FD  0
#define WRITE_FD 1

#define PARENT_READ_FD  ( pipes[PARENT_READ_PIPE][READ_FD]   )
#define PARENT_WRITE_FD ( pipes[PARENT_WRITE_PIPE][WRITE_FD] )

#define CHILD_READ_FD   ( pipes[PARENT_WRITE_PIPE][READ_FD]  )
#define CHILD_WRITE_FD  ( pipes[PARENT_READ_PIPE][WRITE_FD]  )

void setupPipes()
{
    int outfd[2];
    int infd[2];
    
    // pipes for parent to write and read
    pipe(pipes[PARENT_READ_PIPE]);
    pipe(pipes[PARENT_WRITE_PIPE]);
    
    if(!fork()) {
        char *argv[]={ "/Users/james/Downloads/stockfish-6-mac/Mac/stockfish-6-64", 0};
        
        dup2(CHILD_READ_FD, STDIN_FILENO);
        dup2(CHILD_WRITE_FD, STDOUT_FILENO);
        
        /* Close fds not required by child. Also, we don't
         want the exec'ed program to know these existed */
        close(CHILD_READ_FD);
        close(CHILD_WRITE_FD);
        close(PARENT_READ_FD);
        close(PARENT_WRITE_FD);
        
        execv(argv[0], argv);
    } else {
        char buffer[4096];
        int count;
        
        /* close fds not required by parent */
        close(CHILD_READ_FD);
        close(CHILD_WRITE_FD);
        
        count = read(PARENT_READ_FD, buffer, sizeof(buffer)-1);
        if (count >= 0) {
            buffer[count] = 0;
            printf("\n\n-----------------------\n%s\n-----------------------\n\n", buffer);
        } else {
            printf("IO Error\n");
        }
        
        // Write to child’s stdin
        write(PARENT_WRITE_FD, "uci\n", 4);

        // Read from child’s stdout
        count = read(PARENT_READ_FD, buffer, sizeof(buffer)-1);
        if (count >= 0) {
            buffer[count] = 0;
            printf("---%s---", buffer);
        } else {
            printf("IO Error\n");
        }
       
        write(PARENT_WRITE_FD, "go depth 1\n", 11);
        count = read(PARENT_READ_FD, buffer, sizeof(buffer)-1);
        if (count >= 0) {
            buffer[count] = 0;
            printf("\n\n-----------------------\n%s\n-----------------------\n\n", buffer);
        } else {
            printf("IO Error\n");
        }
       
        write(PARENT_WRITE_FD, "go depth 1\n", 11);
        close(PARENT_WRITE_FD);
        count = read(PARENT_READ_FD, buffer, sizeof(buffer)-1);
        if (count >= 0) {
            buffer[count] = 0;
            printf("\n\n-----------------------\n%s\n-----------------------\n\n", buffer);
        } else {
            printf("IO Error\n");
        }
    }
}

Chess::Chess()
{
    setupPipes();
    
    selectedNode = 0;

    board = 0;
    
    whitePawn1 = 0;
    whitePawn2 = 0;
    whitePawn3 = 0;
    whitePawn4 = 0;
    whitePawn5 = 0;
    whitePawn6 = 0;<commit_msg>use c++ string, small changes to commands. seems to be working well<commit_after>//|||||||||||||||||||||||||||||||||||||||||||||||

#include "Chess.h"

#include <OgreLight.h>
#include <OgreWindowEventUtilities.h>
#include "OgreText.h"

/* since pipes are unidirectional, we need two pipes.
 one for data to flow from parent's stdout to child's
 stdin and the other for child's stdout to flow to
 parent's stdin */

#define NUM_PIPES          2

#define PARENT_WRITE_PIPE  0
#define PARENT_READ_PIPE   1

int pipes[NUM_PIPES][2];

/* always in a pipe[], pipe[0] is for read and
 pipe[1] is for write */
#define READ_FD  0
#define WRITE_FD 1

#define PARENT_READ_FD  ( pipes[PARENT_READ_PIPE][READ_FD]   )
#define PARENT_WRITE_FD ( pipes[PARENT_WRITE_PIPE][WRITE_FD] )

#define CHILD_READ_FD   ( pipes[PARENT_WRITE_PIPE][READ_FD]  )
#define CHILD_WRITE_FD  ( pipes[PARENT_READ_PIPE][WRITE_FD]  )

void setupPipes()
{
    int outfd[2];
    int infd[2];
    
    // pipes for parent to write and read
    pipe(pipes[PARENT_READ_PIPE]);
    pipe(pipes[PARENT_WRITE_PIPE]);
    
    if(!fork()) {
        char *argv[]={ "/Users/james/Downloads/stockfish-6-mac/Mac/stockfish-6-64", 0};
        
        dup2(CHILD_READ_FD, STDIN_FILENO);
        dup2(CHILD_WRITE_FD, STDOUT_FILENO);
        
        /* Close fds not required by child. Also, we don't
         want the exec'ed program to know these existed */
        close(CHILD_READ_FD);
        close(CHILD_WRITE_FD);
        close(PARENT_READ_FD);
        close(PARENT_WRITE_FD);
        
        execv(argv[0], argv);
    } else {
        char buffer[4096];
        int count;
        std::string toWrite;

        /* close fds not required by parent */
        close(CHILD_READ_FD);
        close(CHILD_WRITE_FD);
        
        count = read(PARENT_READ_FD, buffer, sizeof(buffer)-1);
        if (count >= 0) {
            buffer[count] = 0;
            printf("\n\n-----------------------\n%s\n-----------------------\n\n", buffer);
        } else {
            printf("IO Error\n");
        }
        
        // Write to child’s stdin
        toWrite = "isready\n";
        write(PARENT_WRITE_FD, toWrite.c_str(), toWrite.length());

        // Read from child’s stdout
        count = read(PARENT_READ_FD, buffer, sizeof(buffer)-1);
        if (count >= 0) {
            buffer[count] = 0;
            printf("---%s---", buffer);
        } else {
            printf("IO Error\n");
        }
       
        toWrite = "ucinewgame\n";
        write(PARENT_WRITE_FD, toWrite.c_str(), toWrite.length());
        toWrite = "position startpos moves e2e4\n";
        write(PARENT_WRITE_FD, toWrite.c_str(), toWrite.length());
        toWrite = "go depth 1\n";
        write(PARENT_WRITE_FD, toWrite.c_str(), toWrite.length());
        
        count = read(PARENT_READ_FD, buffer, sizeof(buffer)-1);
        if (count >= 0) {
            buffer[count] = 0;
            printf("\n\n-----------------------\n%s\n-----------------------\n\n", buffer);
        } else {
            printf("IO Error\n");
        }
    }
}

Chess::Chess()
{
    setupPipes();
    
    selectedNode = 0;

    board = 0;
    
    whitePawn1 = 0;
    whitePawn2 = 0;
    whitePawn3 = 0;
    whitePawn4 = 0;
    whitePawn5 = 0;
    whitePawn6 = 0;
{'fraction_non_alphanumeric': 0.17238725565645682, 'fraction_numerical': 0.01585347083269201, 'mean_word_length': 1.9416025350837482, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1016033', 'n_tokens_mistral': 2342, 'n_tokens_neox': 2220, 'n_words': 483}