Code:
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <windows.h> // WinApi header
#include <cstdio>
#include <string>
#include <time.h>
#include <fstream>
using namespace std;
int findSmallestRemainingElement (int array[], int size, int index);
void swap (int array[], int first_index, int second_index);
void sort (int array[], int size)
{
for ( int i = 0; i < size; i++ )
{
int index = findSmallestRemainingElement( array, size, i );
swap( array, i, index );
}
}
int findSmallestRemainingElement (int array[], int size, int index)
{
int index_of_smallest_value = index;
for (int i = index + 1; i < size; i++)
{
if ( array[ i ] < array[ index_of_smallest_value ] )
{
index_of_smallest_value = i;
}
}
return index_of_smallest_value;
}
void swap (int array[], int first_index, int second_index)
{
int temp = array[ first_index ];
array[ first_index ] = array[ second_index ];
array[ second_index ] = temp;
}
// small helper method to display the before and after arrays
void displayArray (int array[], int size)
{
cout << "{";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "{";
}
file.close();
}
for ( int i = 0; i < size; i++ )
{
// you'll see this pattern a lot for nicely formatting
// lists--check if we're past the first element, and
// if so, append a comma
if ( i != 0 )
{
cout << ", ";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << ", ";
}
file.close();
}
}
cout << array[ i ];
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << array[ i ];
}
file.close();
}
}
cout << "}";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "}";
}
file.close();
}
}
void set_array_value_to_zero ( int array[] )
{
for ( int i = 0; i < 9; i++ )
{
array[ i ] = 0;
}
}
void set_one_string_array_equal_to_another_string_array ( string array[], string array2[] )
{
for ( int i = 0; i < 4; i++ )
{
array[ i ] = array2[ i ];
}
}
void set_one_int_array_equal_to_another_int_array ( int array[], int array2[] )
{
for ( int i = 0; i < 9; i++ )
{
array[ i ] = array2[ i ];
}
}
void newSwitch (int array[], int size, int subtracting_this_many_array_elements, int *high, int *medium, int *low)
{
for ( int i = size; i-- > subtracting_this_many_array_elements; )
{
switch(array[i])
{
case 8:
case 7:
case 6:
//cout << "Input: " << i << " too high\n";
*high += 1;
break;
case 5:
case 4:
case 3:
//cout << "Input: " << i << " might be good\n";
*medium += 1;
break;
case 2:
case 1:
case 0:
//cout << "Input: " << i << " is good\n";
*low += 1;
break;
}
}
}
int which_value_is_largest (int high, int medium, int low)
{
int value = 0;
if ( high > medium && high > low && medium > low )
{
value = 13;
}
else if ( high > medium && high > low && medium == low )
{
value = 12;
}
else if ( high > medium && high > low && low > medium )
{
value = 11;
}
else if ( medium > high && medium > low && high > low )
{
value = 10;
}
else if ( medium > high && medium > low && high == low )
{
value = 9;
}
else if ( medium > high && medium > low && low > high )
{
value = 8;
}
else if ( low > medium && low > high && high > medium )
{
value = 7;
}
else if ( low > medium && low > high && high == medium )
{
value = 6;
}
else if ( low > medium && low > high && medium > high )
{
value = 5;
}
else if ( medium == low && high < medium )
{
value = 4;
}
else if ( high == low && medium < high )
{
value = 3;
}
else if ( high == medium && low < medium )
{
value = 2;
}
else
{
value = 1;
}
return value;
}
int side (int array[], int size, int subtracting_this_many_array_elements)
{
int too_high = 0;
int might_be_good = 0;
int good_stuff = 0;
int value = 0;
//cout << "____________________________________\n";
//cout << "Original array: ";
//displayArray( array, size );
//cout << '\n';
sort( array, size );
//cout << "Sorted array: ";
//displayArray( array, size );
// cout << '\n';
//cout << '\n';
newSwitch( array, size, subtracting_this_many_array_elements, &too_high, &might_be_good, &good_stuff );
//cout << '\n';
//cout << "high counter = " << too_high << '\n';
//cout << "medium counter = " << might_be_good << '\n';
//cout << "low counter = " << good_stuff << '\n';
//cout << '\n';
value = which_value_is_largest (too_high, might_be_good, good_stuff);
//interpreting_whichValueIsLargest(value);
//cout << '\n';
return value;
}
void randomizing_array_elements ( int array[], int size)
{
for ( int i = 0; i < size; i++ )
{
// keep the numbers small so they're easy to read
array[ i ] = rand() % 9;
}
}
int do_this_if_left_or_right_is_greater(int array[], string left_or_right[], int *I_took_a_step, int left_side, int right_side, int subtracting_this_many_array_elements, int which_string_element)
{
int value = 0;
//cout << "____________________________________\n";
//cout << "Left side value is: " << left_side << '\n';
//cout << "Right side value is: " << right_side << '\n';
//cout << '\n';
if ( left_side > right_side )
{
for ( int i = 0; i < 8; i++ )
{
set_array_value_to_zero( array );
randomizing_array_elements(array, 9);
subtracting_this_many_array_elements++;
left_side = side( array, 9, subtracting_this_many_array_elements );
//cout << "Left side value is: " << left_side << '\n';
if (left_side <= 3)
{
//cout << "____________________________________\n";
//cout << "Took a step\n";
value = 1;
*I_took_a_step += 1;
//Beep(1568, 500);
break;
}
else
{
value = 0;
}
//cout << '\n';
}
left_or_right [ which_string_element ] = "left";
}
else if ( right_side > left_side )
{
for ( int i = 0; i < 8; i++ )
{
set_array_value_to_zero( array );
randomizing_array_elements(array, 9);
subtracting_this_many_array_elements++;
right_side = side( array, 9, subtracting_this_many_array_elements );
//cout << "Right side value is: " << right_side << '\n';
if (right_side <= 3)
{
//cout << "____________________________________\n";
//cout << "Took a step\n";
value = 1;
*I_took_a_step += 1;
//Beep(523,500); // 523 hertz (C5) for 500 milliseconds
break;
}
else
{
value = 0;
}
//cout << '\n';
}
left_or_right [ which_string_element ] = "right";
}
return value;
}
int testing_four_directions(int counter[], string left_or_right[], int which_string_element)
{
int array[ 9 ];
int I_took_a_step = 0;
int subtracting_this_many_array_elements = 0;
for ( int i = 0; i < 9; i++ )
{
set_array_value_to_zero( array );
randomizing_array_elements(array, 9);
int left_side = side( array, 9 , subtracting_this_many_array_elements);
set_array_value_to_zero( array );
randomizing_array_elements(array, 9);
int right_side = side( array, 9, subtracting_this_many_array_elements );
while ( left_side == right_side )
{
set_array_value_to_zero( array );
randomizing_array_elements(array, 9);
left_side = side( array, 9 , subtracting_this_many_array_elements);
set_array_value_to_zero( array );
randomizing_array_elements(array, 9);
right_side = side( array, 9, subtracting_this_many_array_elements );
}
int step_counter = do_this_if_left_or_right_is_greater(array, left_or_right, &I_took_a_step, left_side, right_side, subtracting_this_many_array_elements, which_string_element);
counter[ i ] = step_counter;
}
return I_took_a_step;
}
int which_direction_is_lowest(string lowest_value_feeler[], int north, int south, int east, int west, int feeler, int element)
{
int direction_value = 0;
if ( north < south && north < east && north < west )
{
lowest_value_feeler[ element ] = "north";
direction_value = 1;
}
else if ( south < north && south < east && south < west )
{
lowest_value_feeler[ element ] = "south";
direction_value = 2;
}
else if ( east < north && east < south && east < west )
{
lowest_value_feeler[ element ] = "east";
direction_value = 3;
}
else if ( west < north && west < south && west < east )
{
lowest_value_feeler[ element ] = "west";
direction_value = 4;
}
else if ( north == south && north == east && north == west )
{
lowest_value_feeler[ element ] = "no_lowest_direction.";
direction_value = 5;
}
else if ( north == east && north == south )
{
lowest_value_feeler[ element ] = "north_east_south.";
direction_value = 6;
}
else if ( east == south && east == west )
{
lowest_value_feeler[ element ] = "east_south_west.";
direction_value = 7;
}
else if ( south == west && south == north )
{
lowest_value_feeler[ element ] = "south_west_north.";
direction_value = 8;
}
else if ( west == north && west == east )
{
lowest_value_feeler[ element ] = "west_north_east.";
direction_value = 9;
}
else if ( north == east )
{
lowest_value_feeler[ element ] = "north_east.";
direction_value = 10;
}
else if ( east == south )
{
lowest_value_feeler[ element ] = "east_south.";
direction_value = 11;
}
else if ( south == west )
{
lowest_value_feeler[ element ] = "south_west.";
direction_value = 12;
}
else if ( west == north )
{
lowest_value_feeler[ element ] = "west_north.";
direction_value = 13;
}
else if ( west == east )
{
lowest_value_feeler[ element ] = "west_east.";
direction_value = 14;
}
else if ( north == south )
{
lowest_value_feeler[ element ] = "north_south.";
direction_value = 15;
}
else if ( north == east && north > south && north > west )
{
lowest_value_feeler[ element ] = "north_east";
direction_value = 16;
}
else if ( north == west && north > east && north > south )
{
lowest_value_feeler[ element ] = "north_west";
direction_value = 17;
}
else if ( north == south && north > east && north > west )
{
lowest_value_feeler[ element ] = "north_south";
direction_value = 18;
}
else if ( east == west && east > north && east > south )
{
lowest_value_feeler[ element ] = "east_west";
direction_value = 19;
}
else if ( east == south && east > north && east > west )
{
lowest_value_feeler[ element ] = "east_south";
direction_value = 20;
}
else if ( west == south && west > north && west > east )
{
lowest_value_feeler[ element ] = "west_south";
direction_value = 21;
}
return direction_value;
}
void displaying_which_direction_is_lowest( int lowest_value_array[], int direction_value, int feeler )
{
if ( direction_value == 1 )
{
cout << "Feeler " << feeler << " the lowest value is the north direction, so north is blocked." << "\n";
cout << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the displaying_which_direction_is_lowest function" << endl;
}
else
{
file << "Feeler " << feeler << " the lowest value is the north direction, so north is blocked." << "\n";
file << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
}
file.close();
}
else if ( direction_value == 2 )
{
cout << "Feeler " << feeler << " the lowest value is the south direction, so south is blocked." << "\n";
cout << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the displaying_which_direction_is_lowest function" << endl;
}
else
{
file << "Feeler " << feeler << " the lowest value is the south direction, so south is blocked." << "\n";
file << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
}
file.close();
}
else if ( direction_value == 3 )
{
cout << "Feeler " << feeler << " the lowest value is the east direction, so east is blocked." << "\n";
cout << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the displaying_which_direction_is_lowest function" << endl;
}
else
{
file << "Feeler " << feeler << " the lowest value is the east direction, so east is blocked." << "\n";
file << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
}
file.close();
}
else if ( direction_value == 4 )
{
cout << "Feeler " << feeler << " the lowest value is the west direction, so west is blocked." << "\n";
cout << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the displaying_which_direction_is_lowest function" << endl;
}
else
{
file << "Feeler " << feeler << " the lowest value is the west direction, so west is blocked." << "\n";
file << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
}
file.close();
}
else if ( direction_value == 5 )
{
cout << "Feeler " << feeler << " the lowest value is the north, south, east, west direction, so north is blocked." << "\n";
cout << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the displaying_which_direction_is_lowest function" << endl;
}
else
{
file << "Feeler " << feeler << " the lowest value is the north, south, east, west direction, so north is blocked." << "\n";
file << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
}
file.close();
}
else if ( direction_value == 6 )
{
cout << "Feeler " << feeler << " the lowest value is the north, east, south direction, so north is blocked." << "\n";
cout << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the displaying_which_direction_is_lowest function" << endl;
}
else
{
file << "Feeler " << feeler << " the lowest value is the north, east, south direction, so north is blocked." << "\n";
file << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
}
file.close();
}
else if ( direction_value == 7 )
{
cout << "Feeler " << feeler << " the lowest value is the east, south, west direction, so east is blocked." << "\n";
cout << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the displaying_which_direction_is_lowest function" << endl;
}
else
{
file << "Feeler " << feeler << " the lowest value is the east, south, west direction, so east is blocked." << "\n";
file << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
}
file.close();
}
else if ( direction_value == 8 )
{
cout << "Feeler " << feeler << " the lowest value is the south, west, north direction, so south is blocked." << "\n";
cout << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the displaying_which_direction_is_lowest function" << endl;
}
else
{
file << "Feeler " << feeler << " the lowest value is the south, west, north direction, so south is blocked." << "\n";
file << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
}
file.close();
}
else if ( direction_value == 9 )
{
cout << "Feeler " << feeler << " the lowest value is the west, north, east direction, so west is blocked." << "\n";
cout << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the displaying_which_direction_is_lowest function" << endl;
}
else
{
file << "Feeler " << feeler << " the lowest value is the west, north, east direction, so west is blocked." << "\n";
file << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
}
file.close();
}
else if ( direction_value == 10 )
{
cout << "Feeler " << feeler << " the lowest value is the north, east direction, so north is blocked." << "\n";
cout << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the displaying_which_direction_is_lowest function" << endl;
}
else
{
file << "Feeler " << feeler << " the lowest value is the north, east direction, so north is blocked." << "\n";
file << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
}
file.close();
}
else if ( direction_value == 11 )
{
cout << "Feeler " << feeler << " the lowest value is the east, south direction, so east is blocked." << "\n";
cout << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the displaying_which_direction_is_lowest function" << endl;
}
else
{
file << "Feeler " << feeler << " the lowest value is the east, south direction, so east is blocked." << "\n";
file << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
}
file.close();
}
else if ( direction_value == 12 )
{
cout << "Feeler " << feeler << " the lowest value is the south, west direction, so south is blocked." << "\n";
cout << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the displaying_which_direction_is_lowest function" << endl;
}
else
{
file << "Feeler " << feeler << " the lowest value is the south, west direction, so south is blocked." << "\n";
file << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
}
file.close();
}
else if ( direction_value == 13 )
{
cout << "Feeler " << feeler << " the lowest value is the west, north direction, so west is blocked." << "\n";
cout << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the displaying_which_direction_is_lowest function" << endl;
}
else
{
file << "Feeler " << feeler << " the lowest value is the west, north direction, so west is blocked." << "\n";
file << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
}
file.close();
}
else if ( direction_value == 14 )
{
cout << "Feeler " << feeler << " the lowest value is the west, east direction, so west is blocked." << "\n";
cout << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the displaying_which_direction_is_lowest function" << endl;
}
else
{
file << "Feeler " << feeler << " the lowest value is the west, east direction, so west is blocked." << "\n";
file << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
}
file.close();
}
else if ( direction_value == 15 )
{
cout << "Feeler " << feeler << " the lowest value is the north, south direction, so south is blocked." << "\n";
cout << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the displaying_which_direction_is_lowest function" << endl;
}
else
{
file << "Feeler " << feeler << " the lowest value is the north, south direction, so south is blocked." << "\n";
file << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
}
file.close();
}
else if ( direction_value == 16 )
{
cout << "Feeler " << feeler << " the lowest value is the north, east direction, so east is blocked." << "\n";
cout << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the displaying_which_direction_is_lowest function" << endl;
}
else
{
file << "Feeler " << feeler << " the lowest value is the north, east direction, so east is blocked." << "\n";
file << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
}
file.close();
}
else if ( direction_value == 17 )
{
cout << "Feeler " << feeler << " the lowest value is the north, west direction, so north is blocked." << "\n";
cout << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the displaying_which_direction_is_lowest function" << endl;
}
else
{
file << "Feeler " << feeler << " the lowest value is the north, west direction, so north is blocked." << "\n";
file << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
}
file.close();
}
else if ( direction_value == 18 )
{
cout << "Feeler " << feeler << " the lowest value is the north, south direction, so south is blocked." << "\n";
cout << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the displaying_which_direction_is_lowest function" << endl;
}
else
{
file << "Feeler " << feeler << " the lowest value is the north, south direction, so south is blocked." << "\n";
file << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
}
file.close();
}
else if ( direction_value == 19 )
{
cout << "Feeler " << feeler << " the lowest value is the east, west direction, so east is blocked." << "\n";
cout << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the displaying_which_direction_is_lowest function" << endl;
}
else
{
file << "Feeler " << feeler << " the lowest value is the east, west direction, so east is blocked." << "\n";
file << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
}
file.close();
}
else if ( direction_value == 20 )
{
cout << "Feeler " << feeler << " the lowest value is the east, south direction, so south is blocked." << "\n";
cout << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the displaying_which_direction_is_lowest function" << endl;
}
else
{
file << "Feeler " << feeler << " the lowest value is the east, south direction, so south is blocked." << "\n";
file << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
}
file.close();
}
else if ( direction_value == 21 )
{
cout << "Feeler " << feeler << " the lowest value is the west, south direction, so west is blocked." << "\n";
cout << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the displaying_which_direction_is_lowest function" << endl;
}
else
{
file << "Feeler " << feeler << " the lowest value is the west, south direction, so west is blocked." << "\n";
file << "Array element zero is: " << lowest_value_array[ 0 ] << " value\n\n";
}
file.close();
}
}
void direction_value_array_transfer_value_to_new_array (int lowest_value_array[],
string *lowest_value_array_direction,
int north[],
int south[],
int east[],
int west[],
int *direction_value)
{
switch( *direction_value )
{
case 1:
case 5:
case 6:
case 10:
case 17:
set_one_int_array_equal_to_another_int_array ( lowest_value_array, north );
*lowest_value_array_direction = "north";
break;
case 2:
case 8:
case 12:
case 15:
case 18:
case 20:
set_one_int_array_equal_to_another_int_array ( lowest_value_array, south );
*lowest_value_array_direction = "south";
break;
case 3:
case 7:
case 11:
case 16:
case 19:
set_one_int_array_equal_to_another_int_array ( lowest_value_array, east );
*lowest_value_array_direction = "east";
break;
case 4:
case 9:
case 13:
case 14:
case 21:
set_one_int_array_equal_to_another_int_array ( lowest_value_array, west );
*lowest_value_array_direction = "west";
break;
}
}
void display_number_of_steps_message(int north, int south, int east, int west, int which_feeler)
{
cout << "Values with feeler "<< which_feeler << "\n";
cout << "I tried to take 9 steps in the north direction, but I actual took " << north << " steps.\n";
cout << "I tried to take 9 steps in the south direction, but I actual took " << south << " steps.\n";
cout << "I tried to take 9 steps in the east direction, but I actual took " << east << " steps.\n";
cout << "I tried to take 9 steps in the west direction, but I actual took " << west << " steps.\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the display_number_of_steps_message function" << endl;
}
else
{
file << endl;
file << "Values with feeler "<< which_feeler << "\n";
file << "I tried to take 9 steps in the north direction, but I actual took " << north << " steps.\n";
file << "I tried to take 9 steps in the south direction, but I actual took " << south << " steps.\n";
file << "I tried to take 9 steps in the east direction, but I actual took " << east << " steps.\n";
file << "I tried to take 9 steps in the west direction, but I actual took " << west << " steps.\n";
file << endl;
}
file.close();
}
void used_in_setting_feeler_to_new_value ( string left_or_right[],
string lowest_value_feeler[],
int lowest_value_array[],
int north_array[],
int south_array[],
int east_array[],
int west_array[],
string *lowest_value_array_direction,
int *north_count,
int *south_count,
int *east_count,
int *west_count,
int *left_or_right_1,
int *left_or_right_2,
int *left_or_right_3,
int *left_or_right_4,
int *feeler,
int *element )
{
int direction_value = 0;
set_array_value_to_zero( north_array );
set_array_value_to_zero( south_array );
set_array_value_to_zero( east_array );
set_array_value_to_zero( west_array );
set_array_value_to_zero( lowest_value_array );
left_or_right[ *left_or_right_1 ] = "";
left_or_right[ *left_or_right_2 ] = "";
left_or_right[ *left_or_right_3 ] = "";
left_or_right[ *left_or_right_4 ] = "";
*north_count = testing_four_directions(north_array, left_or_right, *left_or_right_1);
*south_count = testing_four_directions(south_array, left_or_right, *left_or_right_2);
*east_count = testing_four_directions(east_array, left_or_right, *left_or_right_3);
*west_count = testing_four_directions(west_array, left_or_right, *left_or_right_4);
direction_value = which_direction_is_lowest(lowest_value_feeler,
*north_count,
*south_count,
*east_count,
*west_count,
*feeler, *element);
direction_value_array_transfer_value_to_new_array ( lowest_value_array,
lowest_value_array_direction,
north_array,
south_array,
east_array,
west_array,
&direction_value);
displaying_which_direction_is_lowest( lowest_value_array, direction_value, *feeler );
}
void fourth_time_setting_feeler_two_element_zero_to_zero ( string left_or_right[],
string lowest_value_feeler_2_try_6[],
int lowest_value_array_feeler_2_try_6[],
int north_array_2_try_6_one_and_odd[],
int south_array_2_try_6_one_and_odd[],
int east_array_2_try_6_one_and_odd[],
int west_array_2_try_6_one_and_odd[],
string *feeler_1_lowest_value_array_direction,
string *feeler_2_lowest_value_array_direction,
string *did_second_feeler_work,
int *north_count_array_2_try_6_one_and_odd,
int *south_count_array_2_try_6_one_and_odd,
int *east_count_array_2_try_6_one_and_odd,
int *west_count_array_2_try_6_one_and_odd,
int *left_or_right_1,
int *left_or_right_2,
int *left_or_right_3,
int *left_or_right_4,
int *feeler,
int *element,
int *the_number_of_loops)
{
while ( 1 )
{
used_in_setting_feeler_to_new_value ( left_or_right,
lowest_value_feeler_2_try_6,
lowest_value_array_feeler_2_try_6,
north_array_2_try_6_one_and_odd,
south_array_2_try_6_one_and_odd,
east_array_2_try_6_one_and_odd,
west_array_2_try_6_one_and_odd,
feeler_2_lowest_value_array_direction,
north_count_array_2_try_6_one_and_odd,
south_count_array_2_try_6_one_and_odd,
east_count_array_2_try_6_one_and_odd,
west_count_array_2_try_6_one_and_odd,
left_or_right_1,
left_or_right_2,
left_or_right_3,
left_or_right_4,
feeler,
element );
if ( lowest_value_array_feeler_2_try_6[ 0 ] == 1)
{
if ( *feeler_2_lowest_value_array_direction != *feeler_1_lowest_value_array_direction )
{
*the_number_of_loops += 1;
*did_second_feeler_work = "elements_are_unequal";
break;
}
}
else
{
*the_number_of_loops += 1;
*did_second_feeler_work = "elements_are_equal";
}
}
}
void third_time_setting_feeler_two_element_zero_to_zero ( string left_or_right[],
string lowest_value_feeler_2_try_5[],
int lowest_value_array_feeler_2_try_5[],
int north_array_2_try_5_one_and_odd[],
int south_array_2_try_5_one_and_odd[],
int east_array_2_try_5_one_and_odd[],
int west_array_2_try_5_one_and_odd[],
string *feeler_1_lowest_value_array_direction,
string *feeler_2_lowest_value_array_direction,
string *did_second_feeler_work,
int *north_count_array_2_try_5_one_and_odd,
int *south_count_array_2_try_5_one_and_odd,
int *east_count_array_2_try_5_one_and_odd,
int *west_count_array_2_try_5_one_and_odd,
int *left_or_right_1,
int *left_or_right_2,
int *left_or_right_3,
int *left_or_right_4,
int *feeler,
int *element,
int *the_number_of_loops)
{
while ( 1 )
{
used_in_setting_feeler_to_new_value ( left_or_right,
lowest_value_feeler_2_try_5,
lowest_value_array_feeler_2_try_5,
north_array_2_try_5_one_and_odd,
south_array_2_try_5_one_and_odd,
east_array_2_try_5_one_and_odd,
west_array_2_try_5_one_and_odd,
feeler_2_lowest_value_array_direction,
north_count_array_2_try_5_one_and_odd,
south_count_array_2_try_5_one_and_odd,
east_count_array_2_try_5_one_and_odd,
west_count_array_2_try_5_one_and_odd,
left_or_right_1,
left_or_right_2,
left_or_right_3,
left_or_right_4,
feeler,
element );
if ( lowest_value_array_feeler_2_try_5[ 0 ] == 0)
{
if ( *feeler_2_lowest_value_array_direction != *feeler_1_lowest_value_array_direction )
{
*the_number_of_loops += 1;
*did_second_feeler_work = "elements_are_unequal";
break;
}
}
else
{
*the_number_of_loops += 1;
*did_second_feeler_work = "elements_are_equal";
}
}
}
int setting_feeler_two_lowest_direction_equal_to_feeler_one_lowest_direction_and_element_zero_to_zero ( string left_or_right[],
string lowest_value_feeler_2_try_4[],
int lowest_value_array_feeler_2_try_4[],
int north_array_2_try_4_zero_and_even[],
int south_array_2_try_4_zero_and_even[],
int east_array_2_try_4_zero_and_even[],
int west_array_2_try_4_zero_and_even[],
string *feeler_1_lowest_value_array_direction,
string *feeler_2_lowest_value_array_direction,
string *did_second_feeler_work,
int *north_count_array_2_try_4_zero_and_even,
int *south_count_array_2_try_4_zero_and_even,
int *east_count_array_2_try_4_zero_and_even,
int *west_count_array_2_try_4_zero_and_even,
int *left_or_right_1,
int *left_or_right_2,
int *left_or_right_3,
int *left_or_right_4,
int *feeler,
int *element,
int *the_number_of_loops)
{
int counter = 0;
while ( 1 )
{
counter = counter + 1;
used_in_setting_feeler_to_new_value ( left_or_right,
lowest_value_feeler_2_try_4,
lowest_value_array_feeler_2_try_4,
north_array_2_try_4_zero_and_even,
south_array_2_try_4_zero_and_even,
east_array_2_try_4_zero_and_even,
west_array_2_try_4_zero_and_even,
feeler_2_lowest_value_array_direction,
north_count_array_2_try_4_zero_and_even,
south_count_array_2_try_4_zero_and_even,
east_count_array_2_try_4_zero_and_even,
west_count_array_2_try_4_zero_and_even,
left_or_right_1,
left_or_right_2,
left_or_right_3,
left_or_right_4,
feeler,
element );
if ( lowest_value_array_feeler_2_try_4[ 0 ] == 0)
{
if ( *feeler_2_lowest_value_array_direction == *feeler_1_lowest_value_array_direction )
{
*the_number_of_loops += 1;
*did_second_feeler_work = "elements_are_equal";
return counter;
}
}
else
{
*the_number_of_loops += 1;
*did_second_feeler_work = "elements_are_unequal";
}
}
}
void second_time_setting_feeler_two_element_zero_to_zero ( string left_or_right[],
string lowest_value_feeler_2_try_3[],
int lowest_value_array_feeler_2_try_3[],
int north_array_2_try_3_zero_and_odd[],
int south_array_2_try_3_zero_and_odd[],
int east_array_2_try_3_zero_and_odd[],
int west_array_2_try_3_zero_and_odd[],
string *feeler_1_lowest_value_array_direction,
string *feeler_2_lowest_value_array_direction,
string *did_second_feeler_work,
int *north_count_array_2_try_3_zero_and_odd,
int *south_count_array_2_try_3_zero_and_odd,
int *east_count_array_2_try_3_zero_and_odd,
int *west_count_array_2_try_3_zero_and_odd,
int *left_or_right_1,
int *left_or_right_2,
int *left_or_right_3,
int *left_or_right_4,
int *feeler,
int *element,
int *the_number_of_loops)
{
while ( 1 )
{
used_in_setting_feeler_to_new_value ( left_or_right,
lowest_value_feeler_2_try_3,
lowest_value_array_feeler_2_try_3,
north_array_2_try_3_zero_and_odd,
south_array_2_try_3_zero_and_odd,
east_array_2_try_3_zero_and_odd,
west_array_2_try_3_zero_and_odd,
feeler_2_lowest_value_array_direction,
north_count_array_2_try_3_zero_and_odd,
south_count_array_2_try_3_zero_and_odd,
east_count_array_2_try_3_zero_and_odd,
west_count_array_2_try_3_zero_and_odd,
left_or_right_1,
left_or_right_2,
left_or_right_3,
left_or_right_4,
feeler,
element );
if ( lowest_value_array_feeler_2_try_3[ 0 ] == 0)
{
if ( *feeler_2_lowest_value_array_direction != *feeler_1_lowest_value_array_direction )
{
*the_number_of_loops += 1;
*did_second_feeler_work = "elements_are_unequal";
break;
}
}
else
{
*the_number_of_loops += 1;
*did_second_feeler_work = "elements_are_equal";
}
}
}
void first_time_setting_feeler_two_element_zero_to_zero ( string left_or_right[],
string lowest_value_feeler_2_try_2[],
int lowest_value_array_feeler_2_try_2[],
int north_array_2_try_2_zero_and_odd[],
int south_array_2_try_2_zero_and_odd[],
int east_array_2_try_2_zero_and_odd[],
int west_array_2_try_2_zero_and_odd[],
string *feeler_1_lowest_value_array_direction,
string *feeler_2_lowest_value_array_direction,
string *did_second_feeler_work,
int *north_count_array_2_try_2_zero_and_odd,
int *south_count_array_2_try_2_zero_and_odd,
int *east_count_array_2_try_2_zero_and_odd,
int *west_count_array_2_try_2_zero_and_odd,
int *left_or_right_1,
int *left_or_right_2,
int *left_or_right_3,
int *left_or_right_4,
int *feeler,
int *element,
int *the_number_of_loops)
{
while ( 1 )
{
used_in_setting_feeler_to_new_value ( left_or_right,
lowest_value_feeler_2_try_2,
lowest_value_array_feeler_2_try_2,
north_array_2_try_2_zero_and_odd,
south_array_2_try_2_zero_and_odd,
east_array_2_try_2_zero_and_odd,
west_array_2_try_2_zero_and_odd,
feeler_2_lowest_value_array_direction,
north_count_array_2_try_2_zero_and_odd,
south_count_array_2_try_2_zero_and_odd,
east_count_array_2_try_2_zero_and_odd,
west_count_array_2_try_2_zero_and_odd,
left_or_right_1,
left_or_right_2,
left_or_right_3,
left_or_right_4,
feeler,
element );
if ( lowest_value_array_feeler_2_try_2[ 0 ] == 0)
{
if ( *feeler_2_lowest_value_array_direction != *feeler_1_lowest_value_array_direction )
{
*the_number_of_loops += 1;
*did_second_feeler_work = "elements_are_unequal";
break;
}
}
else
{
*the_number_of_loops += 1;
*did_second_feeler_work = "elements_are_equal";
}
}
}
void setting_feeler_one_element_zero_to_zero ( string left_or_right[],
string lowest_value_feeler[],
int lowest_value_array[],
int north_array_1_try_2_zero[],
int south_array_1_try_2_zero[],
int east_array_1_try_2_zero[],
int west_array_1_try_2_zero[],
string *feeler_1_lowest_value_array_direction,
string *feeler_2_lowest_value_array_direction,
string *did_second_feeler_work,
int *north_count_array_1_try_2_zero,
int *south_count_array_1_try_2_zero,
int *east_count_array_1_try_2_zero,
int *west_count_array_1_try_2_zero,
int *left_or_right_1,
int *left_or_right_2,
int *left_or_right_3,
int *left_or_right_4,
int *feeler,
int *element,
int *the_number_of_loops)
{
while ( 1 )
{
used_in_setting_feeler_to_new_value ( left_or_right,
lowest_value_feeler,
lowest_value_array,
north_array_1_try_2_zero,
south_array_1_try_2_zero,
east_array_1_try_2_zero,
west_array_1_try_2_zero,
feeler_1_lowest_value_array_direction,
north_count_array_1_try_2_zero,
south_count_array_1_try_2_zero,
east_count_array_1_try_2_zero,
west_count_array_1_try_2_zero,
left_or_right_1,
left_or_right_2,
left_or_right_3,
left_or_right_4,
feeler,
element );
if ( lowest_value_array[ 0 ] == 0 )
{
break;
}
}
}
void direction_value__which_direction_is_lowest__direction_value_array_transfer_value_to_new_array__displaying_which_direction_is_lowest( string lowest_value_feeler[],
int lowest_value_array[],
int north_array[],
int south_array[],
int east_array[],
int west_array[],
string *lowest_value_array_direction,
int *north_count,
int *south_count,
int *east_count,
int *west_count,
int *feeler,
int *element,
int *direction_value )
{
*direction_value = which_direction_is_lowest(lowest_value_feeler,
*north_count,
*south_count,
*east_count,
*west_count,
*feeler,
*element);
direction_value_array_transfer_value_to_new_array ( lowest_value_array,
lowest_value_array_direction,
north_array,
south_array,
east_array,
west_array,
direction_value);
displaying_which_direction_is_lowest( lowest_value_array, *direction_value, *feeler );
}
void the_master_function_part_one ( string lowest_value_feeler_1_try_1[],
string lowest_value_feeler_1_try_2[],
string main_left_or_right[],
int main_north_array[],
int main_south_array[],
int main_east_array[],
int main_west_array[],
string *feeler_one_element_zero_equal,
string *feeler_1_lowest_value_array_direction,
int *main_north_count,
int *main_south_count,
int *main_east_count,
int *main_west_count,
int *less_than_node)
{
string left_or_right[ 20 ];
string lowest_value_feeler_2_try_1[ 9 ];
string lowest_value_feeler_2_try_2[ 9 ];
string lowest_value_feeler_2_try_3[ 9 ];
string lowest_value_feeler_2_try_4[ 9 ];
string lowest_value_feeler_2_try_5[ 9 ];
string feeler_2_lowest_value_array_direction = "";
string did_second_feeler_work = "";
int lowest_value_array_feeler_1_try_1[ 9 ];
int lowest_value_array_feeler_1_try_2[ 9 ];
int lowest_value_array_feeler_2_try_1[ 9 ];
int lowest_value_array_feeler_2_try_2[ 9 ];
int lowest_value_array_feeler_2_try_4[ 9 ];
int lowest_value_array_feeler_2_try_5[ 9 ];
int direction_value = 0;
int feeler = 0;
int element = 0;
int left_or_right_1 = 0;
int left_or_right_2 = 0;
int left_or_right_3 = 0;
int left_or_right_4 = 0;
int north_array_1[ 9 ];
int south_array_1[ 9 ];
int east_array_1[ 9 ];
int west_array_1[ 9 ];
int north_array_2[ 9 ];
int south_array_2[ 9 ];
int east_array_2[ 9 ];
int west_array_2[ 9 ];
int north_array_1_try_2_zero[ 9 ];
int south_array_1_try_2_zero[ 9 ];
int east_array_1_try_2_zero[ 9 ];
int west_array_1_try_2_zero[ 9 ];
int north_array_2_try_2_zero_and_odd[ 9 ];
int south_array_2_try_2_zero_and_odd[ 9 ];
int east_array_2_try_2_zero_and_odd[ 9 ];
int west_array_2_try_2_zero_and_odd[ 9 ];
int north_array_2_try_4_zero_and_even[ 9 ];
int south_array_2_try_4_zero_and_even[ 9 ];
int east_array_2_try_4_zero_and_even[ 9 ];
int west_array_2_try_4_zero_and_even[ 9 ];
int north_array_2_try_5_one_and_odd[ 9 ];
int south_array_2_try_5_one_and_odd[ 9 ];
int east_array_2_try_5_one_and_odd[ 9 ];
int west_array_2_try_5_one_and_odd[ 9 ];
int north_count_1 = 0;
int south_count_1 = 0;
int east_count_1 = 0;
int west_count_1 = 0;
int north_count_2 = 0;
int south_count_2 = 0;
int east_count_2 = 0;
int west_count_2 = 0;
int north_count_array_2_try_2_zero_and_odd = 0;
int south_count_array_2_try_2_zero_and_odd = 0;
int east_count_array_2_try_2_zero_and_odd = 0;
int west_count_array_2_try_2_zero_and_odd = 0;
int north_count_array_2_try_3_zero_and_odd = 0;
int south_count_array_2_try_3_zero_and_odd = 0;
int east_count_array_2_try_3_zero_and_odd = 0;
int west_count_array_2_try_3_zero_and_odd = 0;
int north_count_array_2_try_4_zero_and_even = 0;
int south_count_array_2_try_4_zero_and_even = 0;
int east_count_array_2_try_4_zero_and_even = 0;
int west_count_array_2_try_4_zero_and_even = 0;
int north_count_array_2_try_5_one_and_odd = 0;
int south_count_array_2_try_5_one_and_odd = 0;
int east_count_array_2_try_5_one_and_odd = 0;
int west_count_array_2_try_5_one_and_odd = 0;
int north_count_array_1_try_2_zero = 0;
int south_count_array_1_try_2_zero = 0;
int east_count_array_1_try_2_zero = 0;
int west_count_array_1_try_2_zero = 0;
int the_number_of_loops = 0;
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// starting step 1
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// feeler 1 begin
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
north_count_1 = testing_four_directions(north_array_1, left_or_right, 0);
south_count_1 = testing_four_directions(south_array_1, left_or_right, 1);
east_count_1 = testing_four_directions(east_array_1, left_or_right, 2);
west_count_1 = testing_four_directions(west_array_1, left_or_right, 3);
cout << '\n';
feeler = 1;
element = 0;
direction_value__which_direction_is_lowest__direction_value_array_transfer_value_to_new_array__displaying_which_direction_is_lowest(
lowest_value_feeler_1_try_1,
lowest_value_array_feeler_1_try_1,
north_array_1,
south_array_1,
east_array_1,
west_array_1,
feeler_1_lowest_value_array_direction,
&north_count_1,
&south_count_1,
&east_count_1,
&west_count_1,
&feeler,
&element,
&direction_value );
if ( lowest_value_array_feeler_1_try_1[ 0 ] == 0 )
{
*feeler_one_element_zero_equal = "feeler_one_element_zero_equal_zero";
cout << '\n';
display_number_of_steps_message(north_count_1,
south_count_1,
east_count_1,
west_count_1,
feeler);
cout << "\nstep 1.) change feeler in that direction.\nstep 2.) feel again in that direction\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the the_master_function_part_one function" << endl;
}
else
{
file << "\n\nstep 1.) change feeler in that direction.\nstep 2.) feel again in that direction\n\n";
}
file.close();
cout << '\n';
}
else if ( lowest_value_array_feeler_1_try_1[ 0 ] == 1 )
{
*feeler_one_element_zero_equal = "feeler_one_element_zero_equal_one";
element = 2;
left_or_right_1 = 8;
left_or_right_2 = 9;
left_or_right_3 = 10;
left_or_right_4 = 11;
setting_feeler_one_element_zero_to_zero ( left_or_right,
lowest_value_feeler_1_try_2,
lowest_value_array_feeler_1_try_2,
north_array_1_try_2_zero,
south_array_1_try_2_zero,
east_array_1_try_2_zero,
west_array_1_try_2_zero,
feeler_1_lowest_value_array_direction,
&feeler_2_lowest_value_array_direction,
&did_second_feeler_work,
&north_count_array_1_try_2_zero,
&south_count_array_1_try_2_zero,
&east_count_array_1_try_2_zero,
&west_count_array_1_try_2_zero,
&left_or_right_1,
&left_or_right_2,
&left_or_right_3,
&left_or_right_4,
&feeler,
&element,
&the_number_of_loops);
cout << '\n';
display_number_of_steps_message(north_count_array_1_try_2_zero,
south_count_array_1_try_2_zero,
east_count_array_1_try_2_zero,
west_count_array_1_try_2_zero,
feeler);
cout << '\n';
cout << "\nstep 1.) change feeler in that direction.\nstep 2.) feel again in that direction\n";
cout << '\n';
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the the_master_function_part_one function" << endl;
}
else
{
file << "\n\nstep 1.) change feeler in that direction.\nstep 2.) feel again in that direction\n\n";
}
file.close();
}
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// feeler 1 end
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// feeler 2 begin
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
north_count_2 = testing_four_directions(north_array_2, left_or_right, 4);
south_count_2 = testing_four_directions(south_array_2, left_or_right, 5);
east_count_2 = testing_four_directions(east_array_2, left_or_right, 6);
west_count_2 = testing_four_directions(west_array_2, left_or_right, 7);
cout << '\n';
feeler = 2;
element = 1;
direction_value__which_direction_is_lowest__direction_value_array_transfer_value_to_new_array__displaying_which_direction_is_lowest(
lowest_value_feeler_2_try_1,
lowest_value_array_feeler_2_try_1,
north_array_2,
south_array_2,
east_array_2,
west_array_2,
&feeler_2_lowest_value_array_direction,
&north_count_2,
&south_count_2,
&east_count_2,
&west_count_2,
&feeler,
&element,
&direction_value );
if ( lowest_value_array_feeler_2_try_1[ 0 ] == 0 )
{
cout << '\n';
display_number_of_steps_message(north_count_2,
south_count_2,
east_count_2,
west_count_2,
feeler);
cout << '\n';
}
else if ( lowest_value_array_feeler_2_try_1[ 0 ] == 1 )
{
while ( 1 )
{
element = 3;
left_or_right_1 = 12;
left_or_right_2 = 13;
left_or_right_3 = 14;
left_or_right_4 = 15;
first_time_setting_feeler_two_element_zero_to_zero ( left_or_right,
lowest_value_feeler_2_try_2,
lowest_value_array_feeler_2_try_2,
north_array_2_try_2_zero_and_odd,
south_array_2_try_2_zero_and_odd,
east_array_2_try_2_zero_and_odd,
west_array_2_try_2_zero_and_odd,
feeler_1_lowest_value_array_direction,
&feeler_2_lowest_value_array_direction,
&did_second_feeler_work,
&north_count_array_2_try_2_zero_and_odd,
&south_count_array_2_try_2_zero_and_odd,
&east_count_array_2_try_2_zero_and_odd,
&west_count_array_2_try_2_zero_and_odd,
&left_or_right_1,
&left_or_right_2,
&left_or_right_3,
&left_or_right_4,
&feeler,
&element,
&the_number_of_loops);
if ( lowest_value_array_feeler_2_try_2[ 0 ] == 0)
{
break;
}
}
display_number_of_steps_message(north_count_array_2_try_2_zero_and_odd,
south_count_array_2_try_2_zero_and_odd,
east_count_array_2_try_2_zero_and_odd,
west_count_array_2_try_2_zero_and_odd,
feeler);
}
//////////
cout << '\n';
//results = testing_if_feeler_one_lowest_value_is_same_direction_as_feeler_two_lowest_value ( lowest_value_feeler,
//&did_second_feeler_work,
//&version);
if ( lowest_value_feeler_1_try_1[ 0 ] == lowest_value_feeler_2_try_1 [ 0 ] )
{
did_second_feeler_work = "elements_are_equal";
cout << "The second feeler didn't do anything to unblock feeler 1.\n\n";
cout << "Redo the second feeler until it works.\n\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the the_master_function_part_one function" << endl;
}
else
{
file << "The second feeler didn't do anything to unblock feeler 1.\n\n";
file << "Redo the second feeler until it works.\n\n";
}
file.close();
//cout << "Then testing bulk results to see if one of them solved the feeler 1 block problem.\n";
}
else if ( lowest_value_feeler_1_try_1[ 0 ] != lowest_value_feeler_2_try_1 [ 0 ] )
{
did_second_feeler_work = "elements_are_unequal";
}
else if ( lowest_value_feeler_1_try_2[ 0 ] == lowest_value_feeler_2_try_2 [ 0 ] )
{
did_second_feeler_work = "elements_are_equal";
cout << "The second feeler didn't do anything to unblock feeler 1.\n\n";
cout << "Redo the second feeler until it works.\n\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the the_master_function_part_one function" << endl;
}
else
{
file << "The second feeler didn't do anything to unblock feeler 1.\n\n";
file << "Redo the second feeler until it works.\n\n";
}
file.close();
//cout << "Then testing bulk results to see if one of them solved the feeler 1 block problem.\n";
}
else if ( lowest_value_feeler_1_try_2[ 0 ] != lowest_value_feeler_2_try_2 [ 0 ] )
{
did_second_feeler_work = "elements_are_unequal";
}
// running the second feeler again if it didn't fix the block problem the first time.
////
if ( did_second_feeler_work == "elements_are_equal" )
{
int north_array_2_try_3_zero_and_odd[ 9 ];
int lowest_value_array_feeler_2_try_3[ 9 ];
int south_array_2_try_3_zero_and_odd[ 9 ];
int east_array_2_try_3_zero_and_odd[ 9 ];
int west_array_2_try_3_zero_and_odd[ 9 ];
feeler = 2;
element = 4;
left_or_right_1 = 16;
left_or_right_2 = 17;
left_or_right_3 = 18;
left_or_right_4 = 19;
second_time_setting_feeler_two_element_zero_to_zero ( left_or_right,
lowest_value_feeler_2_try_3,
lowest_value_array_feeler_2_try_3,
north_array_2_try_3_zero_and_odd,
south_array_2_try_3_zero_and_odd,
east_array_2_try_3_zero_and_odd,
west_array_2_try_3_zero_and_odd,
feeler_1_lowest_value_array_direction,
&feeler_2_lowest_value_array_direction,
&did_second_feeler_work,
&north_count_array_2_try_3_zero_and_odd,
&south_count_array_2_try_3_zero_and_odd,
&east_count_array_2_try_3_zero_and_odd,
&west_count_array_2_try_3_zero_and_odd,
&left_or_right_1,
&left_or_right_2,
&left_or_right_3,
&left_or_right_4,
&feeler,
&element,
&the_number_of_loops);
display_number_of_steps_message(north_count_array_2_try_3_zero_and_odd,
south_count_array_2_try_3_zero_and_odd,
east_count_array_2_try_3_zero_and_odd,
west_count_array_2_try_3_zero_and_odd,
feeler);
}
cout << '\n';
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// starting feeler 2 end
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
cout << "The second feeler did something to unblock feeler 1\n\n";
cout << "Step 1 ended = make feeler 1 and 2 unequal - gain control.\n\n";
cout << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the the_master_function_part_one function" << endl;
}
else
{
file << "The second feeler did something to unblock feeler 1\n\n";
file << "Step 1 ended = make feeler 1 and 2 unequal - gain control.\n\n";
file << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
}
file.close();
}
////
// begin test here
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// making the unequal equal again
////
feeler = 2;
element = 5;
left_or_right_1 = 8;
left_or_right_2 = 9;
left_or_right_3 = 10;
left_or_right_4 = 11;
*less_than_node = setting_feeler_two_lowest_direction_equal_to_feeler_one_lowest_direction_and_element_zero_to_zero ( left_or_right,
lowest_value_feeler_2_try_4,
lowest_value_array_feeler_2_try_4,
north_array_2_try_4_zero_and_even,
south_array_2_try_4_zero_and_even,
east_array_2_try_4_zero_and_even,
west_array_2_try_4_zero_and_even,
feeler_1_lowest_value_array_direction,
&feeler_2_lowest_value_array_direction,
&did_second_feeler_work,
&north_count_array_2_try_4_zero_and_even,
&south_count_array_2_try_4_zero_and_even,
&east_count_array_2_try_4_zero_and_even,
&west_count_array_2_try_4_zero_and_even,
&left_or_right_1,
&left_or_right_2,
&left_or_right_3,
&left_or_right_4,
&feeler,
&element,
&the_number_of_loops);
the_number_of_loops = 0;
display_number_of_steps_message(north_count_array_2_try_4_zero_and_even,
south_count_array_2_try_4_zero_and_even,
east_count_array_2_try_4_zero_and_even,
west_count_array_2_try_4_zero_and_even,
feeler);
cout << "Step 2 ended = make feeler 1 and 2 equal - lose control.\n\n";
cout << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the the_master_function_part_one function" << endl;
}
else
{
file << "Step 2 ended = make feeler 1 and 2 equal - lose control.\n\n";
file << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
}
file.close();
}
////
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// making equal unequal again.
////
feeler = 3;
element = 6;
left_or_right_1 = 8;
left_or_right_2 = 9;
left_or_right_3 = 10;
left_or_right_4 = 11;
third_time_setting_feeler_two_element_zero_to_zero ( left_or_right,
lowest_value_feeler_2_try_5,
lowest_value_array_feeler_2_try_5,
north_array_2_try_5_one_and_odd,
south_array_2_try_5_one_and_odd,
east_array_2_try_5_one_and_odd,
west_array_2_try_5_one_and_odd,
feeler_1_lowest_value_array_direction,
&feeler_2_lowest_value_array_direction,
&did_second_feeler_work,
&north_count_array_2_try_5_one_and_odd,
&south_count_array_2_try_5_one_and_odd,
&east_count_array_2_try_5_one_and_odd,
&west_count_array_2_try_5_one_and_odd,
&left_or_right_1,
&left_or_right_2,
&left_or_right_3,
&left_or_right_4,
&feeler,
&element,
&the_number_of_loops);
the_number_of_loops = 0;
display_number_of_steps_message(north_count_array_2_try_5_one_and_odd,
south_count_array_2_try_5_one_and_odd,
east_count_array_2_try_5_one_and_odd,
west_count_array_2_try_5_one_and_odd,
feeler);
cout << "Step 3 ended = make feeler 1 and 2 unequal - regain control.\n\n";
cout << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the the_master_function_part_one function" << endl;
}
else
{
file << "Step 3 ended = make feeler 1 and 2 unequal - regain control.\n\n";
file << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
file << endl;
}
file.close();
}
////
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
cout << '\n';
*main_north_count = north_count_1;
*main_south_count = south_count_1;
*main_east_count = east_count_1;
*main_west_count = west_count_1;
set_one_string_array_equal_to_another_string_array ( main_left_or_right, left_or_right );
set_one_int_array_equal_to_another_int_array ( main_north_array, north_array_1 );
set_one_int_array_equal_to_another_int_array ( main_south_array, south_array_1 );
set_one_int_array_equal_to_another_int_array ( main_east_array, east_array_1 );
set_one_int_array_equal_to_another_int_array ( main_west_array, west_array_1 );
}
void the_master_function_part_two ( string lowest_value_feeler_1_try_1[],
string lowest_value_feeler_1_try_2[],
string main_left_or_right[],
int main_north_array[],
int main_south_array[],
int main_east_array[],
int main_west_array[],
string *feeler_one_element_zero_equal,
string *feeler_1_lowest_value_array_direction,
int *main_north_count,
int *main_south_count,
int *main_east_count,
int *main_west_count,
int *less_than_node,
int *result_of_left_node_test)
{
string left_or_right[ 20 ];
string lowest_value_feeler_2_try_1[ 9 ];
string lowest_value_feeler_2_try_2[ 9 ];
string lowest_value_feeler_2_try_3[ 9 ];
string lowest_value_feeler_2_try_4[ 9 ];
string lowest_value_feeler_2_try_6[ 9 ];
string feeler_2_lowest_value_array_direction = "";
string did_second_feeler_work = "";
int lowest_value_array_feeler_2_try_1[ 9 ];
int lowest_value_array_feeler_2_try_2[ 9 ];
int lowest_value_array_feeler_2_try_4[ 9 ];
int lowest_value_array_feeler_2_try_6[ 9 ];
int direction_value = 0;
int feeler = 0;
int element = 0;
int left_or_right_1 = 0;
int left_or_right_2 = 0;
int left_or_right_3 = 0;
int left_or_right_4 = 0;
int north_array_1[ 9 ];
int south_array_1[ 9 ];
int east_array_1[ 9 ];
int west_array_1[ 9 ];
int north_array_2[ 9 ];
int south_array_2[ 9 ];
int east_array_2[ 9 ];
int west_array_2[ 9 ];
int north_array_2_try_2_zero_and_odd[ 9 ];
int south_array_2_try_2_zero_and_odd[ 9 ];
int east_array_2_try_2_zero_and_odd[ 9 ];
int west_array_2_try_2_zero_and_odd[ 9 ];
int north_array_2_try_4_zero_and_even[ 9 ];
int south_array_2_try_4_zero_and_even[ 9 ];
int east_array_2_try_4_zero_and_even[ 9 ];
int west_array_2_try_4_zero_and_even[ 9 ];
int north_array_2_try_6_one_and_odd[ 9 ];
int south_array_2_try_6_one_and_odd[ 9 ];
int east_array_2_try_6_one_and_odd[ 9 ];
int west_array_2_try_6_one_and_odd[ 9 ];
int north_element_0[ 9 ];
int south_element_0[ 9 ];
int east_element_0[ 9 ];
int west_element_0[ 9 ];
int north_count_2 = 0;
int south_count_2 = 0;
int east_count_2 = 0;
int west_count_2 = 0;
int north_count_array_2_try_2_zero_and_odd = 0;
int south_count_array_2_try_2_zero_and_odd = 0;
int east_count_array_2_try_2_zero_and_odd = 0;
int west_count_array_2_try_2_zero_and_odd = 0;
int north_count_array_2_try_3_zero_and_odd = 0;
int south_count_array_2_try_3_zero_and_odd = 0;
int east_count_array_2_try_3_zero_and_odd = 0;
int west_count_array_2_try_3_zero_and_odd = 0;
int north_count_array_2_try_4_zero_and_even = 0;
int south_count_array_2_try_4_zero_and_even = 0;
int east_count_array_2_try_4_zero_and_even = 0;
int west_count_array_2_try_4_zero_and_even = 0;
int north_count_array_2_try_6_one_and_odd = 0;
int south_count_array_2_try_6_one_and_odd = 0;
int east_count_array_2_try_6_one_and_odd = 0;
int west_count_array_2_try_6_one_and_odd = 0;
int the_number_of_loops = 0;
int greater_than_node = 0;
set_array_value_to_zero( north_element_0 );
set_array_value_to_zero( south_element_0 );
set_array_value_to_zero( east_element_0 );
set_array_value_to_zero( west_element_0 );
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// starting step 1
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
set_one_string_array_equal_to_another_string_array ( left_or_right, main_left_or_right );
set_one_int_array_equal_to_another_int_array ( north_array_1, main_north_array );
set_one_int_array_equal_to_another_int_array ( south_array_1, main_south_array );
set_one_int_array_equal_to_another_int_array ( east_array_1, main_east_array );
set_one_int_array_equal_to_another_int_array ( west_array_1, main_west_array );
north_count_2 = testing_four_directions(north_array_2, left_or_right, 4);
south_count_2 = testing_four_directions(south_array_2, left_or_right, 5);
east_count_2 = testing_four_directions(east_array_2, left_or_right, 6);
west_count_2 = testing_four_directions(west_array_2, left_or_right, 7);
display_number_of_steps_message(north_count_2, south_count_2,east_count_2, west_count_2, 2);
cout << '\n';
feeler = 2;
element = 1;
direction_value__which_direction_is_lowest__direction_value_array_transfer_value_to_new_array__displaying_which_direction_is_lowest(
lowest_value_feeler_2_try_1,
lowest_value_array_feeler_2_try_1,
north_array_2,
south_array_2,
east_array_2,
west_array_2,
&feeler_2_lowest_value_array_direction,
&north_count_2,
&south_count_2,
&east_count_2,
&west_count_2,
&feeler,
&element,
&direction_value );
if ( lowest_value_array_feeler_2_try_1[ 0 ] == 0 )
{
cout << '\n';
display_number_of_steps_message(north_count_2,
south_count_2,
east_count_2,
west_count_2,
feeler);
cout << '\n';
}
else if ( lowest_value_array_feeler_2_try_1[ 0 ] == 1 )
{
while ( 1 )
{
element = 3;
left_or_right_1 = 12;
left_or_right_2 = 13;
left_or_right_3 = 14;
left_or_right_4 = 15;
first_time_setting_feeler_two_element_zero_to_zero ( left_or_right,
lowest_value_feeler_2_try_2,
lowest_value_array_feeler_2_try_2,
north_array_2_try_2_zero_and_odd,
south_array_2_try_2_zero_and_odd,
east_array_2_try_2_zero_and_odd,
west_array_2_try_2_zero_and_odd,
feeler_1_lowest_value_array_direction,
&feeler_2_lowest_value_array_direction,
&did_second_feeler_work,
&north_count_array_2_try_2_zero_and_odd,
&south_count_array_2_try_2_zero_and_odd,
&east_count_array_2_try_2_zero_and_odd,
&west_count_array_2_try_2_zero_and_odd,
&left_or_right_1,
&left_or_right_2,
&left_or_right_3,
&left_or_right_4,
&feeler,
&element,
&the_number_of_loops);
if ( lowest_value_array_feeler_2_try_2[ 0 ] == 0)
{
break;
}
}
}
//////////
cout << '\n';
//results = testing_if_feeler_one_lowest_value_is_same_direction_as_feeler_two_lowest_value ( lowest_value_feeler,
//&did_second_feeler_work,
//&version);
if ( lowest_value_feeler_1_try_1[ 0 ] == lowest_value_feeler_2_try_1 [ 0 ] )
{
did_second_feeler_work = "elements_are_equal";
cout << "The second feeler didn't do anything to unblock feeler 1.\n\n";
cout << "Redo the second feeler until it works.\n\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the the_master_function_part_two function" << endl;
}
else
{
file << "The second feeler didn't do anything to unblock feeler 1.\n\n";
file << "Redo the second feeler until it works.\n\n";
}
file.close();
//cout << "Then testing bulk results to see if one of them solved the feeler 1 block problem.\n";
}
else if ( lowest_value_feeler_1_try_1[ 0 ] != lowest_value_feeler_2_try_1 [ 0 ] )
{
did_second_feeler_work = "elements_are_unequal";
}
else if ( lowest_value_feeler_1_try_2[ 0 ] == lowest_value_feeler_2_try_2 [ 0 ] )
{
did_second_feeler_work = "elements_are_equal";
cout << "The second feeler didn't do anything to unblock feeler 1.\n\n";
cout << "Redo the second feeler until it works.\n\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the the_master_function_part_two function" << endl;
}
else
{
file << "The second feeler didn't do anything to unblock feeler 1.\n\n";
file << "Redo the second feeler until it works.\n\n";
}
file.close();
//cout << "Then testing bulk results to see if one of them solved the feeler 1 block problem.\n";
}
else if ( lowest_value_feeler_1_try_2[ 0 ] != lowest_value_feeler_2_try_2 [ 0 ] )
{
did_second_feeler_work = "elements_are_unequal";
}
// running the second feeler again if it didn't fix the block problem the first time.
////
if ( did_second_feeler_work == "elements_are_equal" )
{
int lowest_value_array_feeler_2_try_3[ 9 ];
int north_array_2_try_3_zero_and_odd[ 9 ];
int south_array_2_try_3_zero_and_odd[ 9 ];
int east_array_2_try_3_zero_and_odd[ 9 ];
int west_array_2_try_3_zero_and_odd[ 9 ];
feeler = 2;
element = 4;
left_or_right_1 = 16;
left_or_right_2 = 17;
left_or_right_3 = 18;
left_or_right_4 = 19;
second_time_setting_feeler_two_element_zero_to_zero ( left_or_right,
lowest_value_feeler_2_try_3,
lowest_value_array_feeler_2_try_3,
north_array_2_try_3_zero_and_odd,
south_array_2_try_3_zero_and_odd,
east_array_2_try_3_zero_and_odd,
west_array_2_try_3_zero_and_odd,
feeler_1_lowest_value_array_direction,
&feeler_2_lowest_value_array_direction,
&did_second_feeler_work,
&north_count_array_2_try_3_zero_and_odd,
&south_count_array_2_try_3_zero_and_odd,
&east_count_array_2_try_3_zero_and_odd,
&west_count_array_2_try_3_zero_and_odd,
&left_or_right_1,
&left_or_right_2,
&left_or_right_3,
&left_or_right_4,
&feeler,
&element,
&the_number_of_loops);
display_number_of_steps_message(north_count_array_2_try_3_zero_and_odd,
south_count_array_2_try_3_zero_and_odd,
east_count_array_2_try_3_zero_and_odd,
west_count_array_2_try_3_zero_and_odd,
feeler);
}
cout << '\n';
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// starting feeler 2 end
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
cout << "The second feeler did something to unblock feeler 1\n\n";
cout << "Step 4 ended = make feeler 1 and 2 unequal - gain control.\n\n";
cout << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the the_master_function_part_two function" << endl;
}
else
{
file << "The second feeler did something to unblock feeler 1\n\n";
file << "Step 4 ended = make feeler 1 and 2 unequal - gain control.\n\n";
file << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
}
file.close();
}
////
// begin test here
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// making the unequal equal again
////
feeler = 2;
element = 5;
left_or_right_1 = 8;
left_or_right_2 = 9;
left_or_right_3 = 10;
left_or_right_4 = 11;
greater_than_node = setting_feeler_two_lowest_direction_equal_to_feeler_one_lowest_direction_and_element_zero_to_zero ( left_or_right,
lowest_value_feeler_2_try_4,
lowest_value_array_feeler_2_try_4,
north_array_2_try_4_zero_and_even,
south_array_2_try_4_zero_and_even,
east_array_2_try_4_zero_and_even,
west_array_2_try_4_zero_and_even,
feeler_1_lowest_value_array_direction,
&feeler_2_lowest_value_array_direction,
&did_second_feeler_work,
&north_count_array_2_try_4_zero_and_even,
&south_count_array_2_try_4_zero_and_even,
&east_count_array_2_try_4_zero_and_even,
&west_count_array_2_try_4_zero_and_even,
&left_or_right_1,
&left_or_right_2,
&left_or_right_3,
&left_or_right_4,
&feeler,
&element,
&the_number_of_loops);
the_number_of_loops = 0;
display_number_of_steps_message(north_count_array_2_try_4_zero_and_even,
south_count_array_2_try_4_zero_and_even,
east_count_array_2_try_4_zero_and_even,
west_count_array_2_try_4_zero_and_even,
feeler);
cout << "Step 5 ended = make feeler 1 and 2 equal - lose control.\n\n";
cout << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the the_master_function_part_two function" << endl;
}
else
{
file << "Step 5 ended = make feeler 1 and 2 equal - lose control.\n\n";
file << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
}
file.close();
}
////
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// making equal unequal again.
////
feeler = 3;
element = 7;
left_or_right_1 = 8;
left_or_right_2 = 9;
left_or_right_3 = 10;
left_or_right_4 = 11;
fourth_time_setting_feeler_two_element_zero_to_zero ( left_or_right,
lowest_value_feeler_2_try_6,
lowest_value_array_feeler_2_try_6,
north_array_2_try_6_one_and_odd,
south_array_2_try_6_one_and_odd,
east_array_2_try_6_one_and_odd,
west_array_2_try_6_one_and_odd,
feeler_1_lowest_value_array_direction,
&feeler_2_lowest_value_array_direction,
&did_second_feeler_work,
&north_count_array_2_try_6_one_and_odd,
&south_count_array_2_try_6_one_and_odd,
&east_count_array_2_try_6_one_and_odd,
&west_count_array_2_try_6_one_and_odd,
&left_or_right_1,
&left_or_right_2,
&left_or_right_3,
&left_or_right_4,
&feeler,
&element,
&the_number_of_loops);
the_number_of_loops = 0;
display_number_of_steps_message(north_count_array_2_try_6_one_and_odd,
south_count_array_2_try_6_one_and_odd,
east_count_array_2_try_6_one_and_odd,
west_count_array_2_try_6_one_and_odd,
feeler);
cout << "Step 3 ended = make feeler 1 and 2 unequal - regain control.\n\n";
cout << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the the_master_function_part_two function" << endl;
}
else
{
file << "Step 6 ended = make feeler 1 and 2 unequal - regain control.\n\n";
file << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
}
file.close();
}
////
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
cout << '\n';
if ( greater_than_node > *less_than_node )
{
cout << "greater than node: " << greater_than_node << ", is greater than less than node: " << *less_than_node << '\n';
cout << "Added left node, start turning.\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the the_master_function_part_two function" << endl;
}
else
{
file << "greater than node: " << greater_than_node << ", is greater than less than node: " << *less_than_node << '\n';
file << "Added left node, start turning.\n";
}
file.close();
*result_of_left_node_test = 0;
}
else if( *less_than_node > greater_than_node )
{
cout << "greater than node: " << greater_than_node << ", is not greater than less than node: " << *less_than_node << '\n';
cout << "Didn\'t add left node, no turning, go straight.\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the the_master_function_part_two function" << endl;
}
else
{
file << "greater than node: " << greater_than_node << ", is not greater than less than node: " << *less_than_node << '\n';
file << "Didn\'t add left node, no turning, go straight.\n";
}
file.close();
*result_of_left_node_test = 1;
}
else
{
cout << "greater than node: " << greater_than_node << ", is equal to less than node: " << *less_than_node << '\n';
cout << "Didn\'t add left node, no turning, go straight.\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the the_master_function_part_two function" << endl;
}
else
{
file << "greater than node: " << greater_than_node << ", is equal to less than node: " << *less_than_node << '\n';
file << "Didn\'t add left node, no turning, go straight.\n";
}
file.close();
*result_of_left_node_test = 1;
}
}
void which_team_scored( int *try_again, int *good_job )
{
if ( *try_again == 0)
{
cout << "\nteam 2 won.\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "\nteam 2 won.\n";
}
file.close();
}
else if ( *try_again == 1 )
{
cout << "\nteam 1 won.\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "\nteam 1 won.\n";
}
file.close();
}
else if ( *try_again % 2 == 0 )
{
cout << "\nteam 2 won.\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "\nteam 2 won.\n";
}
file.close();
}
else if ( *try_again % 2 == 1 )
{
cout << "\nteam 1 won.\n";
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "\nteam 1 won.\n";
}
file.close();
}
}
void display_message_about_stack_layer_part_two( int *stack_layer_one,
int *stack_layer_two,
int *stack_layer_three,
int *stack_layer_four)
{
if ( *stack_layer_one == 0 )
{
cout << "- stack layer 1 value is too low\n";
cout << "meaning it went bad at catching the ball.\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "- stack layer 1 value is too low\n";
file << "meaning it went bad at catching the ball.\n";
}
file.close();
}
}
if ( *stack_layer_two == 0 )
{
cout << "- stack layer 2 value is too low\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "- stack layer 2 value is too low\n";
}
file.close();
}
if ( *stack_layer_one > 0 )
{
cout << "meaning it went bad at controlling the ball once cought.\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "meaning it went bad at controlling the ball once cought.\n";
}
file.close();
}
}
}
if ( *stack_layer_three == 0 )
{
cout << "- stack layer 3 value is too low\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "- stack layer 3 value is too low\n";
}
file.close();
}
if ( (*stack_layer_one > 0) && (*stack_layer_two> 0) )
{
cout << "meaning it went bad at tossing the ball to the other hand to throw.\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "meaning it went bad at tossing the ball to the other hand to throw.\n";
}
file.close();
}
}
}
if ( *stack_layer_four == 0 )
{
cout << "- stack layer 4 value is too low\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "- stack layer 4 value is too low\n";
}
file.close();
}
if ( (*stack_layer_one > 0) && (*stack_layer_two> 0) && (*stack_layer_three > 0 ) )
{
cout << "meaning it went bad at throwing the ball.\n\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "meaning it went bad at throwing the ball.\n\n";
}
file.close();
}
}
}
}
void display_message_about_stack_layer_part_one( int array[],
int *first_array_one_counter,
int *second_array_one_counter,
int *third_array_one_counter,
int *stack_layer_one,
int *stack_layer_two,
int *stack_layer_three,
int *stack_layer_four)
{
if ( (*first_array_one_counter == *second_array_one_counter) && (*first_array_one_counter == *third_array_one_counter) )
{
cout << "\nFirst array needs to change one or more stack layers to a higher one value.\n\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "\nFirst array needs to change one or more stack layers to a higher one value.\n\n";
}
file.close();
}
int counter = 0;
for ( int i = 0; i < 8; i++ )
{
counter += 1;
if ( counter == 1 || counter == 2 )
{
if ( array[ i ] == 1 )
{
*stack_layer_one += 1;
}
}
else if ( counter == 3 || counter == 4 )
{
if ( array[ i ] == 1 )
{
*stack_layer_two += 1;
}
}
else if ( counter == 5 || counter == 6 )
{
if ( array[ i ] == 1 )
{
*stack_layer_three += 1;
}
}
else if ( counter == 7 || counter == 8 )
{
if ( array[ i ] == 1 )
{
*stack_layer_four += 1;
}
}
}
}
if ( (*first_array_one_counter == *second_array_one_counter) && (*first_array_one_counter < *third_array_one_counter) )
{
cout << "\nFirst array needs to change one or more stack layers to a higher one value.\n\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "\nFirst array needs to change one or more stack layers to a higher one value.\n\n";
}
file.close();
}
int counter = 0;
for ( int i = 0; i < 8; i++ )
{
counter += 1;
if ( counter == 1 || counter == 2 )
{
if ( array[ i ] == 1 )
{
*stack_layer_one += 1;
}
}
else if ( counter == 3 || counter == 4 )
{
if ( array[ i ] == 1 )
{
*stack_layer_two += 1;
}
}
else if ( counter == 5 || counter == 6 )
{
if ( array[ i ] == 1 )
{
*stack_layer_three += 1;
}
}
else if ( counter == 7 || counter == 8 )
{
if ( array[ i ] == 1 )
{
*stack_layer_four += 1;
}
}
}
}
if ( (*first_array_one_counter == *second_array_one_counter) && (*first_array_one_counter > *third_array_one_counter) )
{
cout << "\nThird array needs to change one or more stack layers to a higher one value.\n\n";
cout << "\nThis is the right most array on the binary search tree\n";
cout << "That means did you score phase\n\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "\nThird array needs to change one or more stack layers to a higher one value.\n\n";
file << "\nThis is the second right most array on the binary search tree\n";
cout << "That means did you score phase\n\n";
}
file.close();
}
int counter = 0;
for ( int i = 18; i < 26; i++ )
{
counter += 1;
if ( counter == 1 || counter == 2 )
{
if ( array[ i ] == 1 )
{
*stack_layer_one += 1;
}
}
else if ( counter == 3 || counter == 4 )
{
if ( array[ i ] == 1 )
{
*stack_layer_two += 1;
}
}
else if ( counter == 5 || counter == 6 )
{
if ( array[ i ] == 1 )
{
*stack_layer_three += 1;
}
}
else if ( counter == 7 || counter == 8 )
{
if ( array[ i ] == 1 )
{
*stack_layer_four += 1;
}
}
}
}
if ( (*first_array_one_counter == *third_array_one_counter) && (*first_array_one_counter < *second_array_one_counter) )
{
cout << "\nFirst array needs to change one or more stack layers to a higher one value.\n\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "\nFirst array needs to change one or more stack layers to a higher one value.\n\n";
}
file.close();
}
int counter = 0;
for ( int i = 0; i < 8; i++ )
{
counter += 1;
if ( counter == 1 || counter == 2 )
{
if ( array[ i ] == 1 )
{
*stack_layer_one += 1;
}
}
else if ( counter == 3 || counter == 4 )
{
if ( array[ i ] == 1 )
{
*stack_layer_two += 1;
}
}
else if ( counter == 5 || counter == 6 )
{
if ( array[ i ] == 1 )
{
*stack_layer_three += 1;
}
}
else if ( counter == 7 || counter == 8 )
{
if ( array[ i ] == 1 )
{
*stack_layer_four += 1;
}
}
}
}
if ( (*first_array_one_counter == *third_array_one_counter) && (*first_array_one_counter > *second_array_one_counter) )
{
cout << "\nSecond array needs to change one or more stack layers to a higher one value.\n\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "\nSecond array needs to change one or more stack layers to a higher one value.\n\n";
}
file.close();
}
int counter = 0;
for ( int i = 9; i < 17; i++ )
{
counter += 1;
if ( counter == 1 || counter == 2 )
{
if ( array[ i ] == 1 )
{
*stack_layer_one += 1;
}
}
else if ( counter == 3 || counter == 4 )
{
if ( array[ i ] == 1 )
{
*stack_layer_two += 1;
}
}
else if ( counter == 5 || counter == 6 )
{
if ( array[ i ] == 1 )
{
*stack_layer_three += 1;
}
}
else if ( counter == 7 || counter == 8 )
{
if ( array[ i ] == 1 )
{
*stack_layer_four += 1;
}
}
}
}
if ( (*third_array_one_counter == *second_array_one_counter ) && (*first_array_one_counter < *second_array_one_counter ) )
{
cout << "\nFirst array needs to change one or more stack layers to a higher one value.\n\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "\nFirst array needs to change one or more stack layers to a higher one value.\n\n";
}
file.close();
}
int counter = 0;
for ( int i = 0; i < 8; i++ )
{
counter += 1;
if ( counter == 1 || counter == 2 )
{
if ( array[ i ] == 1 )
{
*stack_layer_one += 1;
}
}
else if ( counter == 3 || counter == 4 )
{
if ( array[ i ] == 1 )
{
*stack_layer_two += 1;
}
}
else if ( counter == 5 || counter == 6 )
{
if ( array[ i ] == 1 )
{
*stack_layer_three += 1;
}
}
else if ( counter == 7 || counter == 8 )
{
if ( array[ i ] == 1 )
{
*stack_layer_four += 1;
}
}
}
}
if ( (*third_array_one_counter == *second_array_one_counter ) && (*first_array_one_counter > *second_array_one_counter ) )
{
cout << "\nSecond array needs to change one or more stack layers to a higher one value.\n\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "\nSecond array needs to change one or more stack layers to a higher one value.\n\n";
}
file.close();
}
int counter = 0;
for ( int i = 9; i < 17; i++ )
{
counter += 1;
if ( counter == 1 || counter == 2 )
{
if ( array[ i ] == 1 )
{
*stack_layer_one += 1;
}
}
else if ( counter == 3 || counter == 4 )
{
if ( array[ i ] == 1 )
{
*stack_layer_two += 1;
}
}
else if ( counter == 5 || counter == 6 )
{
if ( array[ i ] == 1 )
{
*stack_layer_three += 1;
}
}
else if ( counter == 7 || counter == 8 )
{
if ( array[ i ] == 1 )
{
*stack_layer_four += 1;
}
}
}
}
if ( (*first_array_one_counter < *second_array_one_counter) && (*first_array_one_counter < *third_array_one_counter) )
{
cout << "\nFirst array needs to change one or more stack layers to a higher one value.\n\n";
cout << "\nThis is the left most array on the binary search tree\n";
cout << "That means this is the catch and control phase\n\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "\nFirst array needs to change one or more stack layers to a higher one value.\n\n";
file << "\nThis is the left most array on the binary search tree\n";
file << "That means this is the catch and control phase\n\n";
}
file.close();
}
int counter = 0;
for ( int i = 0; i < 8; i++ )
{
counter += 1;
if ( counter == 1 || counter == 2 )
{
if ( array[ i ] == 1 )
{
*stack_layer_one += 1;
}
}
else if ( counter == 3 || counter == 4 )
{
if ( array[ i ] == 1 )
{
*stack_layer_two += 1;
}
}
else if ( counter == 5 || counter == 6 )
{
if ( array[ i ] == 1 )
{
*stack_layer_three += 1;
}
}
else if ( counter == 7 || counter == 8 )
{
if ( array[ i ] == 1 )
{
*stack_layer_four += 1;
}
}
}
}
if ( (*second_array_one_counter < *first_array_one_counter ) && (*second_array_one_counter < *third_array_one_counter ) )
{
cout << "\nSecond array needs to change one or more stack layers to a higher one value.\n\n";
cout << "\nThis is the second right most array on the binary search tree\n";
cout << "That means this is the catch and shoot the puck phase\n\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "\nSecond array needs to change one or more stack layers to a higher one value.\n\n";
file << "\nThis is the second right most array on the binary search tree\n";
file << "That means this is the catch and shoot the puck phase\n\n";
}
file.close();
}
int counter = 0;
for ( int i = 9; i < 17; i++ )
{
counter += 1;
if ( counter == 1 || counter == 2 )
{
if ( array[ i ] == 1 )
{
*stack_layer_one += 1;
}
}
else if ( counter == 3 || counter == 4 )
{
if ( array[ i ] == 1 )
{
*stack_layer_two += 1;
}
}
else if ( counter == 5 || counter == 6 )
{
if ( array[ i ] == 1 )
{
*stack_layer_three += 1;
}
}
else if ( counter == 7 || counter == 8 )
{
if ( array[ i ] == 1 )
{
*stack_layer_four += 1;
}
}
}
}
if ( (*third_array_one_counter < *first_array_one_counter ) && (*third_array_one_counter < *second_array_one_counter) )
{
cout << "\nThird array needs to change one or more stack layers to a higher one value.\n\n";
cout << "\nThis is the right most array on the binary search tree\n";
cout << "That means did you score phase\n\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "\nThird array needs to change one or more stack layers to a higher one value.\n\n";
file << "\nThis is the second right most array on the binary search tree\n";
cout << "That means did you score phase\n\n";
}
file.close();
}
int counter = 0;
for ( int i = 18; i < 26; i++ )
{
counter += 1;
if ( counter == 1 || counter == 2 )
{
if ( array[ i ] == 1 )
{
*stack_layer_one += 1;
}
}
else if ( counter == 3 || counter == 4 )
{
if ( array[ i ] == 1 )
{
*stack_layer_two += 1;
}
}
else if ( counter == 5 || counter == 6 )
{
if ( array[ i ] == 1 )
{
*stack_layer_three += 1;
}
}
else if ( counter == 7 || counter == 8 )
{
if ( array[ i ] == 1 )
{
*stack_layer_four += 1;
}
}
}
}
}
void reading_the_results_of_listening_to_the_sound_made_by_the_array_function ( int *zero_counter, int *one_counter )
{
ifstream input("array_used_for_sound.txt");
if( input.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
cout << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
cout << "counting 27 array elements to find 1, 0, value...\n\nresults\n";
cout << "zero = " << *zero_counter << '\n';
cout << "one = " << *one_counter << '\n';
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
file << "counting 27 array elements to find 1, 0, value...\n\nresults\n";
file << "zero = " << *zero_counter << '\n';
file << "one = " << *one_counter << '\n';
}
file.close();
}
if ( *one_counter > *zero_counter )
{
cout << "\none is greater, \nmeaning the winning team actually won in real life.\n\n";
cout << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "\none is greater, \nmeaning the winning team actually won in real life.\n\n";
file << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
}
file.close();
}
}
else
{
cout << "\none is less than or equal to zero value,\nmeaning the winning team actually lost in real life.\n\n";
cout << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "\none is less than or equal to zero value,\nmeaning the winning team actually lost in real life.\n\n";
file << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
}
file.close();
}
int first_array_one_counter = 0;
int first_array_zero_counter = 0;
int second_array_one_counter = 0;
int second_array_zero_counter = 0;
int third_array_one_counter = 0;
int third_array_zero_counter = 0;
int array[ 27 ];
// reading 27 numbers from array file into array so I can count the three arrays zero one values
for ( int i = 0; i < 27; i++ )
{
input >> array[ i ];
}
// input array that does not match the generated array
for ( int i = 0; i < 8; i++ )
{
if ( array [ i ] == 0 )
{
first_array_zero_counter++;
}
else if ( array [ i ] == 1 )
{
first_array_one_counter++;
}
}
// input array that matches the generated array
for ( int i = 9; i < 17; i++ )
{
if ( array [ i ] == 0 )
{
second_array_zero_counter++;
}
else if ( array [ i ] == 1 )
{
second_array_one_counter++;
}
}
// the generated output array
for ( int i = 18; i < 26; i++ )
{
if ( array [ i ] == 0 )
{
third_array_zero_counter++;
}
else if ( array [ i ] == 1 )
{
third_array_one_counter++;
}
}
cout << "\ncounting 24 array elements, not 27\n";
cout << "\n# of 0 in first array = " << first_array_zero_counter << '\n';
cout << "# of 1 in first array = " << first_array_one_counter << '\n';
cout << "\n# of 0 in second array = " << second_array_zero_counter << '\n';
cout << "# of 1 in second array = " << second_array_one_counter << '\n';
cout << "\n# of 0 in third array = " << third_array_zero_counter << '\n';
cout << "# of 1 in third array = " << third_array_one_counter << '\n';
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "\ncounting 24 array elements, not 27\n";
file << "\n# of 0 in first array = " << first_array_zero_counter << '\n';
file << "# of 1 in first array = " << first_array_one_counter << '\n';
file << "\n# of 0 in second array = " << second_array_zero_counter << '\n';
file << "# of 1 in second array = " << second_array_one_counter << '\n';
file << "\n# of 0 in third array = " << third_array_zero_counter << '\n';
file << "# of 1 in third array = " << third_array_one_counter << '\n';
}
file.close();
}
int stack_layer_one = 0;
int stack_layer_two = 0;
int stack_layer_three = 0;
int stack_layer_four = 0;
display_message_about_stack_layer_part_one( array,
&first_array_one_counter,
&second_array_one_counter,
&third_array_one_counter,
&stack_layer_one,
&stack_layer_two,
&stack_layer_three,
&stack_layer_four);
cout << "\nWhich stack layer needs to be changed?\n\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "\nWhich stack layer needs to be changed?\n\n";
}
file.close();
}
display_message_about_stack_layer_part_two( &stack_layer_one,
&stack_layer_two,
&stack_layer_three,
&stack_layer_four);
cout << "\nstack layer 1 value: " << stack_layer_one << '\n';
cout << "\nstack layer 2 value: " << stack_layer_two << '\n';
cout << "\nstack layer 3 value: " << stack_layer_three << '\n';
cout << "\nstack layer 4 value: " << stack_layer_four << '\n' << '\n';
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "\nstack layer 1 value: " << stack_layer_one << '\n';
file << "\nstack layer 2 value: " << stack_layer_two << '\n';
file << "\nstack layer 3 value: " << stack_layer_three << '\n';
file << "\nstack layer 4 value: " << stack_layer_four << '\n' << '\n';
}
file.close();
}
}
input.close();
}
void listening_to_the_sound_made_by_the_array()
{
int zero_counter = 0;
int one_counter = 0;
int i;
int counter = 0;
int counter_to_add_new_sound = 0;
ifstream input("array_used_for_sound.txt");
if( input.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
cout << "\nListen...";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "\nListen...";
}
file.close();
}
while ( input >> i)
{
counter_to_add_new_sound += 1;
counter += 1;
if( counter == 2)
{
Sleep( 400 );
}
else if ( counter == 4 )
{
Sleep( 250 );
}
if ( counter_to_add_new_sound == 4 )
{
Beep(400,210);
Beep(500,210);
Beep(600,210);
}
else if ( counter_to_add_new_sound == 8 )
{
Beep(400,210);
Beep(500,210);
Beep(600,210);
}
else if ( counter_to_add_new_sound == 12 )
{
Beep(400,210);
Beep(500,210);
Beep(600,210);
}
else if ( counter_to_add_new_sound == 16 )
{
Beep(1000,210);
Beep(1100,210);
Beep(1200,210);
counter_to_add_new_sound = 0;
}
if ( i == 0 )
{
zero_counter += 1;
Beep(400,150);
}
else if ( i == 1 )
{
one_counter += 1;
Beep(900, 150);
}
counter = 0;
}
input.close();
cout << "I can hear it!\n\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "I can hear it!\n\n";
}
file.close();
}
for ( int i = 0; i < zero_counter; i+= 1 )
{
Beep(400,150);
}
for ( int i = 0; i < one_counter; i+= 1 )
{
Beep(900, 150);
}
reading_the_results_of_listening_to_the_sound_made_by_the_array_function( &zero_counter, &one_counter );
}
void writing_array_to_file_to_listen_to_after_program_ends( int array[])
{
for ( int i = 0; i < 9; i++ )
{
fstream file("array_used_for_sound.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << array[ i ] << endl;
}
file.close();
}
}
int displaying_the_test_results_from_running_the_two_main_function(
int compare_to_output_array_1[],
int compare_to_output_array_2[],
int the_random_list_generated_by_the_left_node_results_array[],
int *counting_matching_array_elements_1,
int *counting_matching_array_elements_2,
int *counting_left_nodes_1,
int *counting_left_nodes_2,
int *try_again,
int *good_job)
{
int break_or_not = 0;
if ( *counting_matching_array_elements_1 > *counting_matching_array_elements_2 )
{
if ( *counting_left_nodes_1 < *counting_left_nodes_2 )
{
cout << "\nThe goal is to match the results array to the input array\n";
cout << "with the least left nodes.\n";
cout << "That goal was met: Good job!.\n\n";
cout << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
cout << "This is the results generated array:\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "\nThe goal is to match the results array to the input array\n";
file << "with the least left nodes.\n";
file << "That goal was met: Good job!.\n\n";
file << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
file << "This is the results generated array:\n";
}
file.close();
}
displayArray( the_random_list_generated_by_the_left_node_results_array, 9 );
cout << '\n';
cout << "\nThis is the best matching input array:\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << '\n';
file << "\nThis is the best matching input array:\n";
}
file.close();
}
writing_array_to_file_to_listen_to_after_program_ends( compare_to_output_array_2);
writing_array_to_file_to_listen_to_after_program_ends( compare_to_output_array_1);
writing_array_to_file_to_listen_to_after_program_ends( the_random_list_generated_by_the_left_node_results_array);
displayArray( compare_to_output_array_1, 9 );
*good_job += 1;
break_or_not = 1;
}
else
{
cout << "\nThe goal is to match the results array to the input array\n";
cout << "with the least left nodes.\n";
cout << "That goal was not met: Try again.\n\n";
cout << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
cout << "This is the results generated array:\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "\nThe goal is to match the results array to the input array\n";
file << "with the least left nodes.\n";
file << "That goal was not met: Try again.\n\n";
file << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
file << "This is the results generated array:\n";
}
file.close();
}
displayArray( the_random_list_generated_by_the_left_node_results_array, 9 );
cout << '\n';
cout << "\nThis is the best matching input array:\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << '\n';
file << "\nThis is the best matching input array:\n";
}
file.close();
}
displayArray( compare_to_output_array_1, 9 );
*try_again += 1;
}
}
else if ( *counting_matching_array_elements_2 > *counting_matching_array_elements_1 )
{
if ( *counting_left_nodes_2 < *counting_left_nodes_1 )
{
cout << "The goal is to match the results array to the input array\n";
cout << "with the least left nodes.\n";
cout << "That goal was met: Good job!.\n\n";
cout << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
cout << "This is the results generated array:\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "The goal is to match the results array to the input array\n";
file << "with the least left nodes.\n";
file << "That goal was met: Good job!.\n\n";
file << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
file << "This is the results generated array:\n";
}
file.close();
}
displayArray( the_random_list_generated_by_the_left_node_results_array, 9 );
cout << '\n';
cout << "\nThis is the best matching input array:\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << '\n';
file << "\nThis is the best matching input array:\n";
}
file.close();
}
writing_array_to_file_to_listen_to_after_program_ends( compare_to_output_array_1);
writing_array_to_file_to_listen_to_after_program_ends( compare_to_output_array_2);
writing_array_to_file_to_listen_to_after_program_ends( the_random_list_generated_by_the_left_node_results_array);
displayArray( compare_to_output_array_2, 9 );
*good_job += 1;
break_or_not = 1;
}
else
{
cout << "\nThe goal is to match the results array to the input array\n";
cout << "with the least left nodes.\n";
cout << "That goal was not met: Try again.\n\n";
cout << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
cout << "This is the results generated array:\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "\nThe goal is to match the results array to the input array\n";
file << "with the least left nodes.\n";
file << "That goal was not met: Try again.\n\n";
file << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
file << "This is the results generated array:\n";
}
file.close();
}
displayArray( the_random_list_generated_by_the_left_node_results_array, 9 );
cout << '\n';
cout << "\nThis is the best matching input array:\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << '\n';
file << "\nThis is the best matching input array:\n";
}
file.close();
}
displayArray( compare_to_output_array_2, 9 );
*try_again += 1;
}
}
return break_or_not;
}
void running_the_two_main_functions( int compare_to_output_array_1[],
int compare_to_output_array_2[],
int the_random_list_generated_by_the_left_node_results_array[],
int *try_again,
int *good_job )
{
string lowest_value_feeler_1_try_1[ 9 ];
string lowest_value_feeler_1_try_2[ 9 ];
string left_or_right[ 4 ];
int north_array[ 9 ];
int south_array[ 9 ];
int east_array[ 9 ];
int west_array[ 9 ];
string feeler_1_lowest_value_array_direction = "";
string feeler_one_element_zero_equal = "";
int north_count_1 = 0;
int south_count_1 = 0;
int east_count_1 = 0;
int west_count_1 = 0;
int less_than_node = 0;
int result_of_left_node_test = 0;
while ( 1 )
{
north_count_1 = 0;
south_count_1 = 0;
east_count_1 = 0;
west_count_1 = 0;
less_than_node = 0;
result_of_left_node_test = 0;
int counting_matching_array_elements_1 = 0;
int counting_matching_array_elements_2 = 0;
int counting_left_nodes_1 = 0;
int counting_left_nodes_2 = 0;
for ( int i = 0; i < 9; i++ )
{
the_master_function_part_one(lowest_value_feeler_1_try_1,
lowest_value_feeler_1_try_2,
left_or_right,
north_array,
south_array,
east_array,
west_array,
&feeler_one_element_zero_equal,
&feeler_1_lowest_value_array_direction,
&north_count_1,
&south_count_1,
&east_count_1,
&west_count_1,
&less_than_node);
the_master_function_part_two(lowest_value_feeler_1_try_1,
lowest_value_feeler_1_try_2,
left_or_right,
north_array,
south_array,
east_array,
west_array,
&feeler_one_element_zero_equal,
&feeler_1_lowest_value_array_direction,
&north_count_1,
&south_count_1,
&east_count_1,
&west_count_1,
&less_than_node,
&result_of_left_node_test);
the_random_list_generated_by_the_left_node_results_array[ i ] = result_of_left_node_test;
}
for ( int i = 0; i < 9; i++ )
{
// keep the numbers small so they're easy to read
compare_to_output_array_2[ i ] = rand() % 2;
}
for ( int i = 0; i < 9; i++ )
{
// counting left nodes in the 2 arrays
if ( compare_to_output_array_1[ i ] == 0 )
{
counting_left_nodes_1 += 1;
}
if ( compare_to_output_array_2[ i ] == 0 )
{
counting_left_nodes_2 += 1;
}
// comparing the elements of the two arrays to the results array to find matching elements
if (compare_to_output_array_1[ i ] == the_random_list_generated_by_the_left_node_results_array [ i ] )
{
counting_matching_array_elements_1 += 1;
}
if (compare_to_output_array_2[ i ] == the_random_list_generated_by_the_left_node_results_array[ i ] )
{
counting_matching_array_elements_2 += 1;
}
}
int break_or_not = displaying_the_test_results_from_running_the_two_main_function(
compare_to_output_array_1,
compare_to_output_array_2,
the_random_list_generated_by_the_left_node_results_array,
&counting_matching_array_elements_1,
&counting_matching_array_elements_2,
&counting_left_nodes_1,
&counting_left_nodes_2,
try_again,
good_job);
if ( break_or_not == 1 )
{
break;
}
}
}
int main ()
{
int compare_to_output_array_1[ 9 ];
int compare_to_output_array_2[ 9 ];
int the_random_list_generated_by_the_left_node_results_array[ 9 ];
int try_again = 0;
int good_job = 0;
srand( time( NULL ) );
set_array_value_to_zero( compare_to_output_array_1 );
set_array_value_to_zero( compare_to_output_array_2 );
set_array_value_to_zero( the_random_list_generated_by_the_left_node_results_array );
// clear text file
{
fstream file("text_from_program.txt", ios::out | ios::trunc);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
file.close();
}
// clear text file
{
fstream file("array_used_for_sound.txt", ios::out | ios::trunc);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
file.close();
}
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
cout << "Starting program\n";
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "Starting program\n\n";
}
file.close();
}
for ( int i = 0; i < 9; i++ )
{
// keep the numbers small so they're easy to read
compare_to_output_array_1[ i ] = rand() % 2;
}
running_the_two_main_functions( compare_to_output_array_1,
compare_to_output_array_2,
the_random_list_generated_by_the_left_node_results_array,
&try_again,
&good_job );
cout << '\n';
cout << "\ngenerated input list 1\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << '\n';
file << "\ngenerated input list 1\n";
}
file.close();
}
displayArray( compare_to_output_array_1, 9 );
cout << '\n';
cout << "generated input list 2\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << '\n';
file << "generated input list 2\n";
}
file.close();
}
displayArray( compare_to_output_array_2, 9 );
cout << '\n';
cout << "generated results list\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << '\n';
file << "generated results list\n";
}
file.close();
}
displayArray( the_random_list_generated_by_the_left_node_results_array, 9 );
cout << "\n\n";
cout << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
cout << "\n\nscore:\n";
cout << "Number of times won = " << good_job << '\n';
cout << "Number of retries until won = " << try_again << '\n';
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "\n\n";
file << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
file << "\n\nscore:\n";
file << "Number of times won = " << good_job << '\n';
file << "Number of retries until won = " << try_again << '\n';
}
file.close();
}
which_team_scored( &try_again, &good_job );
cout << "\nEnding program\n\n";
cout << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
cout << "Begin analysis of the sound the 27 array elements make.\n\n";
cout << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
{
fstream file("text_from_program.txt", ios::in | ios::out | ios::app);
if( file.fail() )
{
cout << "error while opening the file in the main function" << endl;
}
else
{
file << "\n\n";
file << "\nEnding program\n\n";
file << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
file << "Begin analysis of the sound the 27 array elements make.\n\n";
file << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
}
file.close();
}
cout << "listening to the sound the arrays make\n";
listening_to_the_sound_made_by_the_array();
getchar();
}