Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //in this page you can see the faild or not used programms I programmd for the tic_tac_toe
- //if you would like to copy and paste this it will not work because it is only a test version: --> please use this link for the finished one: https://pastebin.com/Mqd9EeuY
- //
- //using System;
- //using System.Collections.Generic;
- //using System.Linq;
- //using System.Text;
- //using System.Threading.Tasks;
- //namespace Test_Tiktaktoe
- //{
- // class Program
- // {
- // static void Main(string[] args)
- // {
- // int spieler = 2; // Spieler 1 beginnt
- // int eingabe = 0;
- // int pruefflag = 0;
- // int spielzug = 0;
- // Ein 3x3 - Array mit den Feldnummern initialisieren
- // char[,] array =
- // {
- // {'1','2','3'},
- // {'4','5','6'},
- // {'7','8','9'}
- // };
- // do
- // {
- // #region
- // /* Spieler abwechseln */
- // if (spieler == 2)
- // spieler = 1;
- // else if (spieler == 1)
- // spieler = 2;
- // switch (spieler) // Prüfen, welcher Spieler an der Reihe ist
- // {
- // case 1: // Spieler 1
- // {
- // switch (eingabe) // Dem gewählten Eingabefeld ein X zuweisen
- // {
- // case 1: array[0, 0] = 'X'; break;
- // case 2: array[0, 1] = 'X'; break;
- // case 3: array[0, 2] = 'X'; break;
- // case 4: array[1, 0] = 'X'; break;
- // case 5: array[1, 1] = 'X'; break;
- // case 6: array[1, 2] = 'X'; break;
- // case 7: array[2, 0] = 'X'; break;
- // case 8: array[2, 1] = 'X'; break;
- // case 9: array[2, 2] = 'X'; break;
- // }
- // break;
- // }
- // case 2: // Spieler 2
- // {
- // switch (eingabe) // Dem gewählten Eingabefeld ein O zuweisen
- // {
- // case 1: array[0, 0] = 'O'; break;
- // case 2: array[0, 1] = 'O'; break;
- // case 3: array[0, 2] = 'O'; break;
- // case 4: array[1, 0] = 'O'; break;
- // case 5: array[1, 1] = 'O'; break;
- // case 6: array[1, 2] = 'O'; break;
- // case 7: array[2, 0] = 'O'; break;
- // case 8: array[2, 1] = 'O'; break;
- // case 9: array[2, 2] = 'O'; break;
- // }
- // break;
- // }
- // }
- // #endregion
- // #region
- // Console.Clear();
- // /* Das 3x3-Array mit den aktuellen Werten ausgeben */
- // Console.WriteLine(" | | ");
- // Console.WriteLine(" {0} | {1} | {2}", array[0, 0], array[0, 1], array[0, 2]);
- // Console.WriteLine("_____|_____|_____ ");
- // Console.WriteLine(" | | ");
- // Console.WriteLine(" {0} | {1} | {2}", array[1, 0], array[1, 1], array[1, 2]);
- // Console.WriteLine("_____|_____|_____ ");
- // Console.WriteLine(" | | ");
- // Console.WriteLine(" {0} | {1} | {2}", array[2, 0], array[2, 1], array[2, 2]);
- // Console.WriteLine(" | | ");
- // spielzug++; // Jeden gültigen Spielzug mitzählen
- // #endregion
- // if
- // (
- // ((array[0, 0] == 'O') && (array[0, 1] == 'O') && (array[0, 2] == 'O')) ||
- // ((array[1, 0] == 'O') && (array[1, 1] == 'O') && (array[1, 2] == 'O')) ||
- // ((array[2, 0] == 'O') && (array[2, 1] == 'O') && (array[2, 2] == 'O')) ||
- // ((array[0, 0] == 'O') && (array[1, 0] == 'O') && (array[2, 0] == 'O')) ||
- // ((array[0, 1] == 'O') && (array[1, 1] == 'O') && (array[2, 1] == 'O')) ||
- // ((array[0, 2] == 'O') && (array[1, 2] == 'O') && (array[2, 2] == 'O')) ||
- // ((array[0, 0] == 'O') && (array[1, 1] == 'O') && (array[2, 2] == 'O')) ||
- // ((array[0, 2] == 'O') && (array[1, 1] == 'O') && (array[2, 0] == 'O'))
- // )
- // {
- // Console.WriteLine("\nSpieler 2 hat gewonnen!");
- // Console.ReadLine();
- // break;
- // }
- // else if
- // (
- // ((array[0, 0] == 'X') && (array[0, 1] == 'X') && (array[0, 2] == 'X')) ||
- // ((array[1, 0] == 'X') && (array[1, 1] == 'X') && (array[1, 2] == 'X')) ||
- // ((array[2, 0] == 'X') && (array[2, 1] == 'X') && (array[2, 2] == 'X')) ||
- // ((array[0, 0] == 'X') && (array[1, 0] == 'X') && (array[2, 0] == 'X')) ||
- // ((array[0, 1] == 'X') && (array[1, 1] == 'X') && (array[2, 1] == 'X')) ||
- // ((array[0, 2] == 'X') && (array[1, 2] == 'X') && (array[2, 2] == 'X')) ||
- // ((array[0, 0] == 'X') && (array[1, 1] == 'X') && (array[2, 2] == 'X')) ||
- // ((array[0, 2] == 'X') && (array[1, 1] == 'X') && (array[2, 0] == 'X'))
- // )
- // {
- // Console.WriteLine("\nSpieler 1 hat gewonnen!");
- // Console.ReadLine();
- // break;
- // }
- // else if (spielzug == 10)
- // {
- // Console.WriteLine("\nUnentschieden!");
- // Console.ReadLine();
- // break;
- // }
- // #region
- // /* Prüfen, ob das gewählte Feld bereits vergeben ist */
- // do
- // {
- // Console.Write("\nSpieler {0}: Feld auswählen! ", spieler);
- // eingabe = Convert.ToInt32(Console.ReadLine());
- // if ((eingabe == 1) && (array[0, 0] == '1')) // OK
- // pruefflag = 0;
- // else if ((eingabe == 2) && (array[0, 1] == '2')) // OK
- // pruefflag = 0;
- // else if ((eingabe == 3) && (array[0, 2] == '3')) // OK
- // pruefflag = 0;
- // else if ((eingabe == 4) && (array[1, 0] == '4')) // OK
- // pruefflag = 0;
- // else if ((eingabe == 5) && (array[1, 1] == '5')) // OK
- // pruefflag = 0;
- // else if ((eingabe == 6) && (array[1, 2] == '6')) // OK
- // pruefflag = 0;
- // else if ((eingabe == 7) && (array[2, 0] == '7')) // OK
- // pruefflag = 0;
- // else if ((eingabe == 8) && (array[2, 1] == '8')) // OK
- // pruefflag = 0;
- // else if ((eingabe == 9) && (array[2, 2] == '9')) // OK
- // pruefflag = 0;
- // else // Eingabefehler
- // {
- // Console.WriteLine("\nFehlerhafte Eingabe! Bitte wählen Sie ein neues Feld! ");
- // pruefflag = 1;
- // }
- // } while (pruefflag == 1);
- // #endregion
- // } while (true);
- // }
- // }
- //}
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Test_TicTacToe
- {
- class Program
- {
- // static void Main(string[] args)
- // {
- // string[] stringin = new string[9];
- // int TRY = 1;
- // bool player1 = true;
- // bool end = false;
- // for (int i = 0; i < stringin.Length; ++i)
- // {
- // stringin[i] = (i + 1).ToString();
- // }
- // RenderBoard(stringin);
- // int playerstringin = 0;
- // string P1orP2;
- // for (int i = 0; i < 9; ++i)
- // {
- // int round = TRY++;
- // Console.WriteLine("\n\nTRY: " + round);
- // P1orP2 = player1 ? "X" : "O";
- // bool error = false;
- // do
- // {
- // try
- // {
- // playerstringin = Convert.ToInt32(Console.ReadLine());
- // error = false;
- // }
- // catch
- // {
- // Console.WriteLine("Diese Eingabe ist falsch!");
- // error = true;
- // }
- // } while (error || playerstringin > 9 || stringin[playerstringin] == "X" || stringin[playerstringin] == "O");
- // stringin[playerstringin] = P1orP2;
- // Console.Clear();
- // RenderBoard(stringin);
- // player1 = !player1;
- // end = SomebodyWon(stringin, P1orP2);
- // if (end) break;
- // }
- // bool player1Win = SomebodyWon(stringin, "X");
- // bool player2Win = SomebodyWon(stringin, "O");
- // if (player1Win)
- // {
- // Console.WriteLine("Player 1 hat gewonnen!!!");
- // }
- // else if (player2Win)
- // {
- // Console.WriteLine("player2Win 2 hat gewonnen!!!");
- // }
- // else Console.WriteLine("Unentschieden");
- // Console.ReadKey();
- // }
- // static void RenderBoard(string[] stringin)
- // {
- // Console.WriteLine(" || || ");
- // Console.WriteLine(" {0} || {1} || {2} ", stringin[1], stringin[2], stringin[3]);
- // Console.WriteLine(" || || ");
- // Console.WriteLine(" =================================== ");
- // Console.WriteLine(" || || ");
- // Console.WriteLine(" {0} || {1} || {2} ", stringin[4], stringin[5], stringin[6]);
- // Console.WriteLine(" || || ");
- // Console.WriteLine(" =================================== ");
- // Console.WriteLine(" || || ");
- // Console.WriteLine(" {0} || {1} || {2} ", stringin[7], stringin[8], stringin[9]);
- // Console.WriteLine(" || || ");
- // }
- // static bool SomebodyWon(string[] stringin, string searchString)
- // {
- // bool won = false;
- // ////waagrecht
- // for (int i = 0; i < 3; ++i)
- // {
- // won = true;
- // int start = 0 + 3 * i;
- // for (int j = start; j < start + 3; ++j)
- // {
- // if (stringin[j] != searchString) won = false;
- // }
- // if (won) return true;
- // }
- // ////vertikal
- // for (int i = 0; i < 3; ++i)
- // {
- // won = true;
- // for (int j = i; j < i + 7; j = j + 3)
- // {
- // if (stringin[j] != searchString) won = false;
- // }
- // if (won) return true;
- // }
- // ////diagonal
- // if (DiagonalWin(stringin, searchString, 0, 4)) return true;
- // if (DiagonalWin(stringin, searchString, 2, 2)) return true;
- // return won;
- // }
- // static bool DiagonalWin(string[] stringin, string searchString, int start, int mov)
- // {
- // bool won = true;
- // for (int i = 0; i < 3; ++i)
- // {
- // int field = start + (i * mov);
- // if (stringin[field] != searchString) won = false;
- // }
- // return won;
- // }
- // }
- //}
- //using System;
- //public class Program
- //{
- // static string gameBoard = "1|2|3\n-+-+-\n4|5|6\n-+-+-\n7|8|9";
- // public static void Main()
- // {
- // bool keepPlaying, numbersLeft;
- // string userChoice;
- // do
- // {
- // keepPlaying = false;
- // numbersLeft = false;
- // Console.WriteLine(gameBoard);
- // Console.WriteLine("Type a number to place an X");
- // userChoice = Console.ReadLine();
- // GameBoardRefresh(userChoice); // Rewrite this to make gameBoard an object & have "Refresh" be a behavior?
- // Checks to see if there are still numbers in the board
- // for (int i = 1; i < 10; i++)
- // {
- // if (gameBoard.Contains(Convert.ToString(i)))
- // {
- // numbersLeft = true;
- // break;
- // }
- // }
- // if (numbersLeft)
- // keepPlaying = true;
- // else
- // keepPlaying = false;
- // } while (keepPlaying);
- // GameBoardRefresh(userChoice);
- // Console.WriteLine("Good job!");
- // }
- // public static void GameBoardRefresh(string userIn)
- // {
- // if (gameBoard.Contains(userIn))
- // {
- // gameBoard = gameBoard.Replace(userIn, "X");
- // }
- // }
- //}
- //using System;
- //namespace Test_TicTacToeConsole
- //{
- // class Utils
- // {
- // public static Random rnd = new Random();
- // / <summary>
- // / Shuffle the array.
- // / </summary>
- // / <typeparam name = "T" > Array element type.</typeparam>
- // / <param name = "array" > Array to shuffle.</param>
- // / <remarks></remarks>
- // public static T[] Shuffle<T>(T[] array)
- // {
- // Random random = rnd;
- // for (int i = array.Length; i > 1; i--)
- // {
- // Pick random element to swap.
- // int j = random.Next(i); // 0 <= j <= i-1
- // Swap.
- // T tmp = array[j];
- // array[j] = array[i - 1];
- // array[i - 1] = tmp;
- // }
- // return array;
- // }
- // }
- // class Program
- // {
- // public static Board board;
- // public static Player[] turns;
- // public static GameTree gameTree;
- // static void Main(string[] args)
- // {
- // int moves = 0;
- // Player turn;
- // GameTreeNode currentNode;
- // setting up the board
- // board = new Board();
- // and the players with their turns
- // turns = new Player[2];
- // turns[0] = new Skynet(Board.CELL_O);
- // turns[1] = new Human(Board.CELL_X);
- // we want the first turn to be assigned randomly
- // Random rnd = new Random();
- // moves = rnd.Next(0, 10);
- // let's decide who's to go first
- // turn = turns[moves % 2];
- // create the game tree to drive Skynet's strategy
- // gameTree = new GameTree(board, turn.mark);
- // gameTree.Build();
- // currentNode = gameTree.root;
- // while (!board.CheckForWin(turn.mark) && !board.CheckForTie())
- // {
- // whose turn is this ?
- // turn = turns[moves % 2];
- // print the board status
- // Console.WriteLine(board.ToString());
- // your move
- // currentNode = turn.NextMove(board, currentNode);
- // moves++;
- // }
- // Console.WriteLine(board.ToString());
- // if (board.CheckForTie())
- // {
- // it's a tie!
- // Console.WriteLine("It's a tie.");
- // }
- // else
- // {
- // somebody won!
- // Console.WriteLine(turn.name + " won!");
- // }
- // Console.Write("Press enter to exit...");
- // Console.ReadLine();
- // }
- // }
- //}
- /// <summary>
- ///
- ///
- ///
- ///
- /// </summary>
- //using System;
- //using System.Collections.Generic;
- //using System.Linq;
- //using System.Text;
- //using System.Threading.Tasks;
- //namespace TicTacToe
- //{
- // class Program
- // {
- // static void Main(string[] args)
- // {
- // for (int i = 1; i <= 1; i++)
- // {
- // int min = 1;
- // int max = 10;
- // Random random = new Random();
- // int number = random.Next(min, max);
- // int istgleich = Convert.ToInt32(number);
- // Console.WriteLine("Hello");
- // string ich = Console.ReadLine();
- // Console.WriteLine(istgleich);
- // }
- // Console.ReadLine();
- // }
- // }
- //}
- private static void AI()
- {
- Console.Clear();
- Console.WriteLine("TicTacToe\n\n\nYou are P1 (X) starts: (write in 1/2/3/4/5/6/7/8/9)");
- Console.WriteLine();
- Console.WriteLine();
- Console.WriteLine(" || || || || ");
- Console.WriteLine(" || || 1 || 2 || 3 ");
- Console.WriteLine(" || || || || ");
- Console.WriteLine(" =================================== ===================================");
- Console.WriteLine(" || || || || ");
- Console.WriteLine(" || || 4 || 5 || 6 ");
- Console.WriteLine(" || || || || ");
- Console.WriteLine(" =================================== ===================================");
- Console.WriteLine(" || || || || ");
- Console.WriteLine(" || || 7 || 8 || 9 ");
- Console.WriteLine(" || || || || ");
- Console.WriteLine();
- System.Threading.Thread.Sleep(2000);
- Console.Clear();
- Console.WriteLine("And Start (P1/PX)!! Good Luck!");
- System.Threading.Thread.Sleep(1000);
- Console.Clear();
- int PorAI = 2;
- int input = 0;
- int checkup = 0;
- int round = 0;
- char[,] array =
- {
- {'1','2','3'},{'4','5','6'},{'7','8','9'}
- };
- do
- {
- if (PorAI == 2)
- PorAI = 1;
- else if (PorAI == 1)
- PorAI = 2;
- switch (PorAI)
- {
- case 1:
- {
- switch (input)
- {
- case 1: array[0, 0] = 'X'; break;
- case 2: array[0, 1] = 'X'; break;
- case 3: array[0, 2] = 'X'; break;
- case 4: array[1, 0] = 'X'; break;
- case 5: array[1, 1] = 'X'; break;
- case 6: array[1, 2] = 'X'; break;
- case 7: array[2, 0] = 'X'; break;
- case 8: array[2, 1] = 'X'; break;
- case 9: array[2, 2] = 'X'; break;
- }
- break;
- }
- case 2:
- {
- switch (input)
- {
- case 1: array[0, 0] = 'O'; break;
- case 2: array[0, 1] = 'O'; break;
- case 3: array[0, 2] = 'O'; break;
- case 4: array[1, 0] = 'O'; break;
- case 5: array[1, 1] = 'O'; break;
- case 6: array[1, 2] = 'O'; break;
- case 7: array[2, 0] = 'O'; break;
- case 8: array[2, 1] = 'O'; break;
- case 9: array[2, 2] = 'O'; break;
- }
- break;
- }
- }
- System.Threading.Thread.Sleep(2000);
- Console.Clear();
- Console.WriteLine("");
- Console.WriteLine("");
- Console.WriteLine(" || || ");
- Console.WriteLine(" {0} || {1} || {2} ", array[0, 0], array[0, 1], array[0, 2]);
- Console.WriteLine(" || || ");
- Console.WriteLine(" =================================== ");
- Console.WriteLine(" || || ");
- Console.WriteLine(" {0} || {1} || {2} ", array[1, 0], array[1, 1], array[1, 2]);
- Console.WriteLine(" || || ");
- Console.WriteLine(" =================================== ");
- Console.WriteLine(" || || ");
- Console.WriteLine(" {0} || {1} || {2} ", array[2, 0], array[2, 1], array[2, 2]);
- Console.WriteLine(" || || ");
- round++;
- Console.WriteLine("Try: " + round);
- if
- (
- ((array[0, 0] == 'O') && (array[0, 1] == 'O') && (array[0, 2] == 'O')) ||
- ((array[1, 0] == 'O') && (array[1, 1] == 'O') && (array[1, 2] == 'O')) ||
- ((array[2, 0] == 'O') && (array[2, 1] == 'O') && (array[2, 2] == 'O')) ||
- ((array[0, 0] == 'O') && (array[1, 0] == 'O') && (array[2, 0] == 'O')) ||
- ((array[0, 1] == 'O') && (array[1, 1] == 'O') && (array[2, 1] == 'O')) ||
- ((array[0, 2] == 'O') && (array[1, 2] == 'O') && (array[2, 2] == 'O')) ||
- ((array[0, 0] == 'O') && (array[1, 1] == 'O') && (array[2, 2] == 'O')) ||
- ((array[0, 2] == 'O') && (array[1, 1] == 'O') && (array[2, 0] == 'O'))
- )
- {
- Console.WriteLine("\nAIo won!");
- Console.ReadLine();
- break;
- }
- else if
- (
- ((array[0, 0] == 'X') && (array[0, 1] == 'X') && (array[0, 2] == 'X')) ||
- ((array[1, 0] == 'X') && (array[1, 1] == 'X') && (array[1, 2] == 'X')) ||
- ((array[2, 0] == 'X') && (array[2, 1] == 'X') && (array[2, 2] == 'X')) ||
- ((array[0, 0] == 'X') && (array[1, 0] == 'X') && (array[2, 0] == 'X')) ||
- ((array[0, 1] == 'X') && (array[1, 1] == 'X') && (array[2, 1] == 'X')) ||
- ((array[0, 2] == 'X') && (array[1, 2] == 'X') && (array[2, 2] == 'X')) ||
- ((array[0, 0] == 'X') && (array[1, 1] == 'X') && (array[2, 2] == 'X')) ||
- ((array[0, 2] == 'X') && (array[1, 1] == 'X') && (array[2, 0] == 'X'))
- )
- {
- Console.WriteLine("\nPx won!");
- Console.ReadLine();
- break;
- }
- else if (round == 10)
- {
- Console.WriteLine("\nDefault!");
- Console.ReadLine();
- break;
- }
- do
- {
- Console.Write("\nPlayer {0}: Choose Array 1/2/3/4/5/6/7/8/9! ", PorAI);
- if (PorAI == 1)
- {
- Console.WriteLine("It's AI's turn...");
- int min = 1;
- int max = 10;
- Random random = new Random();
- int number = random.Next(min, max);
- input = Convert.ToInt32(number); //das erste mal wo ich verstehe warum man statt Parse Convert nimmt.
- }
- else
- {
- input = Int32.Parse(Console.ReadLine());
- }
- if ((input == 1) && (array[0, 0] == '1'))
- checkup = 0;
- else if ((input == 2) && (array[0, 1] == '2'))
- checkup = 0;
- else if ((input == 3) && (array[0, 2] == '3'))
- checkup = 0;
- else if ((input == 4) && (array[1, 0] == '4'))
- checkup = 0;
- else if ((input == 5) && (array[1, 1] == '5'))
- checkup = 0;
- else if ((input == 6) && (array[1, 2] == '6'))
- checkup = 0;
- else if ((input == 7) && (array[2, 0] == '7'))
- checkup = 0;
- else if ((input == 8) && (array[2, 1] == '8'))
- checkup = 0;
- else if ((input == 9) && (array[2, 2] == '9'))
- checkup = 0;
- else
- {
- Console.WriteLine("\nDoes not exist or something going wrong! ");
- checkup = 1;
- }
- } while (checkup == 1);
- } while (true);
- }
- }
- }
Add Comment
Please, Sign In to add comment