Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- using namespace std;
- //מדריך צבעים https://www.youtube.com/watch?v=IXtm7cI21vM
- void setcolor(unsigned short color){
- HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(hcon, color);
- }
- enum status{empty, white, black};
- enum status main_board [7][6]; /// i,j // הוא 0 j השורה הכי עליונה היא השורה בה
- void reset_board(enum status board [7][6]){
- for(int i=0; i<7; i++){
- for(int j=0; j<6; j++){
- board[i][j] = empty;
- }
- }
- }
- void show(enum status board [7][6]){
- cout<<"\n\n1234567\n_______\n";
- for(int j=0; j<6; j++){
- for(int i=0; i<7; i++){
- if(board[i][j]== empty) cout<<"@";
- else if (board[i][j]== white) {
- setcolor(11);
- cout<<"w";
- setcolor(7);
- }
- else {
- setcolor(12);
- cout<<"b";
- setcolor(7);
- }
- }
- cout<<"\n";
- }
- cout<<"\n";
- }
- int get_from_player(enum status stat){
- show(main_board);
- if (stat==white) cout<<"-White move.\n";
- else cout<<"-Black move.\n";
- int location;
- cout <<"Enter location: ";
- cin>> location;
- while(location<1 || location>7 || main_board[location-1][0] != empty){
- cout<<"Please enter a legal location: ";
- cin >> location;
- }
- cout<<"\n";
- return location-1;
- }
- void Put_in_a_move(enum status board [7][6], int location, enum status stat){
- for(int j=5; j>=0; j--){
- if (board[location][j] == empty){
- board[location][j] = stat;
- break;
- }
- }
- }
- enum status Victory_check (enum status board [7][6]){
- for(int j=5; j>=0; j--){
- for(int i=0; i<4; i++){
- if (board[i][j]==empty) continue;
- for(int b=i+1, q=0; q<3; q++, b++){
- if (board[i][j]!=board[b][j]) break;
- if(q==2) return board[i][j];
- }
- }
- }
- // עד כאן בדיקת ניצחונות אופקיים
- for(int i=0; i<7; i++){
- for(int j=5; j>2; j--){
- if (board[i][j]==empty) continue;
- for(int b=j-1, q=0; q<3; q++, b--){
- if (board[i][j]!=board[i][b]) break;
- if(q==2) return board[i][j];
- }
- }
- }
- // עד כאן בדיקת ניצחונות ישרים
- for(int j=5; j>2; j--){
- for(int i=0; i<4; i++){
- if (board[i][j]==empty) continue;
- for(int q=1; q<4; q++){
- if (board[i][j]!=board[i+q][j-q]) break;
- if(q==3) return board[i][j];
- }
- }
- }
- // עד כאן אלכסון משמאל נמוך לימין גבוה
- for(int j=5; j>2; j--){
- for(int i=3; i<7; i++){
- if (board[i][j]==empty) continue;
- for(int q=1; q<4; q++){
- if (board[i][j]!=board[i-q][j-q]) break;
- if(q==3) return board[i][j];
- }
- }
- }
- // עד כאן אלכסון מימין נמוך לשמאל גבוה
- return empty;
- }
- void main(){
- enum status VictoryFlag = empty;
- reset_board(main_board);
- //show(main_board);
- int Count_of_actions = 0, loc;
- do{
- loc = get_from_player(white);
- Put_in_a_move(main_board, loc, white);
- VictoryFlag = Victory_check(main_board);
- if (VictoryFlag != empty) break;
- Count_of_actions++;
- if(Count_of_actions==42) break;
- loc = get_from_player(black);
- Put_in_a_move(main_board, loc, black);
- VictoryFlag = Victory_check(main_board);
- if (VictoryFlag != empty) break;
- Count_of_actions++;
- }while(Count_of_actions<42);
- show(main_board);
- if (VictoryFlag==white) {setcolor(11); cout<<"White won!!!!!\n\n\n\n"; setcolor(7);}
- else if (VictoryFlag==black) {setcolor(12); cout<<"Black won!!!!!\n\n\n\n"; setcolor(7);}
- else {setcolor(15); cout<<"End! No win.\n\n\n\n"; setcolor(7);}
- }
Advertisement
Add Comment
Please, Sign In to add comment