I am trying to prepare a Turtle graphics solution in C#. Everything is working fine but it ends in Process Terminated due to StackOverflowException. I checked this
and
this
where the issue is of getter setter or infinite loop. But I dont have any of this condition in my code. I am a newbie in C#.
Below is my code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TurtleGraphics
{
class Program
{/**
* Directions: 0 right, 1 down, 2 left, 3 up
*/
private static short direction = 0;
private static bool penDown;
private static int turtleX = 0, turtleY = 0;
private static int[,] floor = new int[20, 20];
public static void Main(String[] args)
{
initFloor(floor);
//Scanner in = new Scanner(System.in);
printMenu();
int nextCommand = int.Parse(Console.ReadLine());
while (nextCommand != 9)
{
switch (nextCommand)
{
case 1:
penDown = false;
break;
case 2:
penDown = true;
break;
case 3:
direction++;
break;
case 4:
direction--;
break;
case 5:
Console.WriteLine("How many steps do you want to move?");
int move = int.Parse(Console.ReadLine());
if (move <= 10)
while (--move != 0)
Moves();
break;
case 6:
printArray();
break;
default:
Console.WriteLine("Unknow command, please try again:\n");
break;
}
Moves();
Console.WriteLine("What's next?");
nextCommand = int.Parse(Console.ReadLine());
}
}
private static void initFloor(int[,] floor)
{
for (int i = 0; i < floor.GetLength(0); i++)
{
for (int j = 0; j < floor.GetLength(1); j++)
{
floor[i,j] = 0;
}
}
}
private static void printMenu()
{
Console.WriteLine("Commands List:\n\n\t1 Pen up\n"
+ "\t2 Pen down\n"
+ "\t3 Turn right\n"
+ "\t4 Turn left\n"
+ "\t5 to 10 Move forward 10 spaces (replace 10 for a different number of spaces)\n"
+ "\t6 Display the 20-by-20 array\n"
+ "\t9 End of data (sentinel)Please enter a command number:\n");
}
private static void printArray()
{
for (int i = 0; i < floor.GetLength(0); i++)
{
for (int j = 0; j < floor.GetLength(1); j++)
{
// Console.WriteLine(floor[i, j]);
// Console.WriteLine(" ");
if (floor[i, j] == 0)
Console.Write(".");
else if (floor[i, j] == 1)
Console.Write("*");
else if (floor[i, j] == 2)
Console.Write("T");
}
Console.WriteLine();
}
}
private static void Moves()
{
switch (direction)
{
case 0:
turtleX++;
break;
case 1:
turtleY++;
break;
case 2:
turtleX--;
break;
case 3:
turtleY--;
break;
default:
if (direction < 0)
direction = 3;
else
direction = 4;
Moves();
break;
}
if (penDown)
{
if (turtleX < 20 && turtleY < 20)
floor[turtleX, turtleY] = 1;
else
{
direction -= 2;
Moves();
}
}
}
}
}
Any quick help is appreciated. Thanks
There's one obvious situation where you end up looping endlessly. Imagine you're entering the Moves method and direction is 4:
private static void Moves()
{
switch (direction)
{
case 0:
//Nope
case 1:
//Nope
case 2:
//Nope
case 3:
//Nope
default:
if (direction < 0)
//Nope
else
direction = 4; //Okay, but it already was
Moves(); //And call myself again
The code cannot make any further progress and the call stack fills up with more and more calls to Moves() that are never going to finish.
I can't offer a correction because I don't understand what your code is meant to be doing. Break it down into smaller methods with clearer method names and XML documentation comments that describe what it does. Then makes sure that the code and comments agree.
I have no idea what the correct operation of a method called Moves is.
The default section of the switch statement in Moves should be this:
default:
if (direction < 0)
direction += 4;
else
direction -= 4;
Moves();
break;
since its purpose is to wrap the direction value such that it always remains in the range 0-3.
Related
public int MaxNumberOfBalloons(string text)
{
// arr = {b, a, l, o, n}
int[] arr = new int[5];
foreach (char ch in text)
{
switch (ch)
{
case 'b':
Console.WriteLine(ch);
arr[0]++;
break;
case 'a':
arr[1]++;
break;
case 'l':
arr[2]++;
break;
case 'o':
arr[3]++;
break;
case 'n':
arr[4]++;
break;
default:
break;
}
}
int counter = 0;
Console.WriteLine("Before");
displayArr(arr);
while (checkArr(arr))
{
foreach (int i in arr)
{
if (i == 2 || i == 3)
{
arr[i] -= 2;
}
else
{
arr[i]--;
}
}
counter++;
}
Console.WriteLine("After");
displayArr(arr);
return counter;
}
public bool checkArr(int[] arr)
{
for (int i = 0; i < arr.Length; i++)
{
if (i == 2)
{
if (arr[i] > 1)
continue;
else
return false;
}
if (i == 3)
{
if (arr[i] > 1)
continue;
else
return false;
}
if (arr[i] == 0)
return false;
}
return true;
}
Test results for input string: text = "bb"
Console output before the while loop:
b
b
Before
0
2
2
2
2
After the while loop:
After
0
2
2
2
2
counter returned 1.
Question: Why is the switch statement not working as expected?
Observation: Is increasing all the other index except for the one that is supposed to. I wrote a Console.WriteLine in the case that is suppose to land twice and it did, but it increased all the other index except for that one.
The display method is very straight forward: A simple iterator that outputs the content of each index in the array passed to it.
In the main, I just simply call the MaxNumberOfBalloons method and pass it a string.
I think the issue is with displayArr.
If I change it to:
for (int i = 0; i < arr.Length; i++)
{
Console.WriteLine(arr[i]);
}
You are not printing the array but the index of the array based on the value of the array.
It works correctly.
So instead of printing arr[0], which is 2; you are printing arr[arr[0]] which is the same as arr[2], which is 0.
foreach (int i in arr)
{
Console.WriteLine(i);
}
This is a very interesting bug and took me a while to see.
I really don't know how to phrase my title, help me out.
I am having an issue with a game I am making. The game's objective is to eat an apple that appears on the map for points. When you eat it, another apple appears in a random location inside the little box.
As you see the apple goes out of the bounds. But it doesn't always happen on the first time I get to it. Also, there is a # at the very far right for some reason.
Here is the code:
The drawing happens in the Draw() method, so you should look at that first.
using System;
public class MainClass
{
public const int WIDTH = 20, HEIGHT = 20;
public static int Points, X, Y, FruitX, FruitY;
public static bool GameOver = false;
public static string Direction;
public static Random Rand = new Random();
public static void Start()
{
Console.Clear();
GameOver = false;
Direction = "Stop";
X = WIDTH/2;
Y = HEIGHT/2;
FruitX = Rand.Next(100)%WIDTH/2;
FruitY = Rand.Next(100)%HEIGHT/2;
}
public static void Draw()
{
Console.Clear();
for (int i = 0; i < WIDTH; i++)
{
Console.Write("# ");
}
for (int i = 0; i < HEIGHT - 1; i++)
{
for (int j = 0; j < WIDTH; j++)
{
Console.Write(j == 0 ? "# " : " ");
if (j == WIDTH - 1)
{
Console.Write("# ");
}
if (i == Y && j == X)
{
Console.Write("O");
}
else if (i == FruitY && j == FruitX)
{
Console.Write("🍎");
}
else
{
Console.Write(" ");
}
}
Console.WriteLine();
}
for (int i = 0; i < WIDTH + 1; i++)
{
Console.Write("# ");
}
Console.WriteLine($"\nPoints: {Points}");
}
public static void InputHandler()
{
ConsoleKeyInfo UserInput = Console.ReadKey();
switch (UserInput.KeyChar)
{
case 'w':
Direction = "Up";
break;
case 'a':
Direction = "Left";
break;
case 's':
Direction = "Down";
break;
case 'd':
Direction = "Right";
break;
case 'x':
GameOver = true;
break;
default:
break;
}
}
public static void GameHandler()
{
switch (Direction)
{
case "Up":
Y--;
break;
case "Down":
Y++;
break;
case "Left":
X--;
break;
case "Right":
X++;
break;
default:
break;
}
GameOver = X > WIDTH || X < 0 || Y < 0 || Y > HEIGHT;
if (X == FruitX && Y == FruitY)
{
Points += 10;
FruitX = Rand.Next(100)%WIDTH/2;
FruitY = Rand.Next(100)%HEIGHT/2;
}
}
public static void Main(string[] args)
{
Start();
while (!GameOver)
{
Draw();
InputHandler();
GameHandler();
}
Console.Clear();
}
}
I am new at programming and I'm trying to create a Menu that has inside Submenus. The main Menu has all the options to procede while the submenu has a CRUD for each options inserted.
However the submenu I've done(Animals)doesn't work neither of the visualize by id methods and it goes like this to the following crud methods for the submenus. Also when a submenu complets its tasks it should return to the initial Submenu options, allowing to return to main Menu by pressing zero. Which is not happening, though I tryied doing things differently. I'm not sure if it's the switch statement which wrong or if it's the methods call.
Sorry if the code is a little bigger than usual:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace menu
{
class Program
{
public static int id = 1;
enum animalHeader { id, name, client_name, type_animal };
enum clientHeader { id, name, client_surname, adrress };
static void Main(string[] args)
{
string[,] animal = new string[20, 4];
string[,] client = new string[20, 6];
do { MenuOptions(animal); } while (true);
}
static void MenuOptions(string[,] animal)
{
int userChoice;
do
{
Console.Clear();
Console.WriteLine("\nChoose one of the following options:\n");
Console.WriteLine("[ 1 ] Animals");
Console.WriteLine("[ 2 ] Clients");
Console.WriteLine("[ 0 ] Quit application\n");
} while (!int.TryParse(Console.ReadLine(), out userChoice) || userChoice < 0 || userChoice > 2);
Console.Clear();
switch (userChoice)
{
case 1:
menuAnimal(animal);
menuReturn(animal);
break;
case 2:
//menuClient(client);
mainMenu();
break;
case 0:
Environment.Exit(0);
break;
default:
Console.WriteLine("Try again!!");
break;
}
}
static void menuAnimal(string[,] animal)
{
int optAnimal;
do
{
Console.Clear();
Console.WriteLine("\nInsert one of the following options:\n");
Console.WriteLine("[ 1 ] Insert animal");
Console.WriteLine("[ 2 ] See animal");
Console.WriteLine("[ 3 ] Alter animal");
Console.WriteLine("[ 4 ] Erase animal");
Console.WriteLine("[ 5 ] List animals");
Console.WriteLine("[ 0 ] Return to main menu\n");
} while (!int.TryParse(Console.ReadLine(), out optAnimal) || optAnimal < 0 || optAnimal > 5);
Console.Clear();
switch (optAnimal)
{
case 1:
insertData(animal);
menuReturn(animal);
break;
case 2:
visualizeByid(animal);
menuReturn(animal);
break;
case 3:
updateById(animal);
menuReturn(animal);
break;
case 4:
deleteByid(animal);
menuReturn(animal);
break;
case 5:
listData(animal);
menuReturn(animal);
break;
}
}
static void mainMenu()
{
Console.Clear();
Console.ReadKey();
}
static void menuReturn(string[,] animal)
{
Console.Clear();
do { menuAnimal(animal); } while (true);
}
static int generateId()
{
return id++;
}
static int getInsertIndex(string[,] matrix)
{
for (int j = 0; j < matrix.GetLength(0) - 1; j++)
{
if (string.IsNullOrEmpty(matrix[j, 0])) return j;
}
return -1;
}
static void insertData(string[,] matrix)
{
int id = generateId();
int n = getInsertIndex(matrix);
matrix[n, 0] = Convert.ToString(id);
for (int j = 1; j < matrix.GetLength(1); j++)
{
do
{
Console.Write($"Insert {Enum.GetName(typeof(animalHeader), j)}: ");
matrix[n, j] = Console.ReadLine();
} while (String.IsNullOrEmpty(matrix[n, j]));
}
}
static int searchId(string[,] matrix)
{
int choosenId, index = -1;
do
{
Console.Write("Insert ID to continue: ");
} while (!int.TryParse(Console.ReadLine(), out choosenId));
for (int i = 0; i < matrix.GetLength(0); i++)
{
if (Convert.ToString(choosenId) == matrix[i, 0])
{
index = i;
}
}
return index;
}
static void visualizeByid(string[,] matrix)
{
int pos = searchId(matrix);
if (pos != -1)
{
for (int i = pos; i < pos + 1; i++)
{
for (int j = 0; j < matrix.GetLength(1); j++)
{
Console.Write($"{matrix[i, j]}\t");
}
Console.WriteLine();
}
}
else { Console.WriteLine("Wrong Id"); }
}
static void updateById(string[,] matrix)
{
int pos = searchId(matrix);
if (pos != -1)
{
for (int i = pos; i < pos + 1; i++)
{
for (int j = 1; j < matrix.GetLength(1); j++)
{
Console.Write($"Insert {Enum.GetName(typeof(animalHeader), j)}: ");
matrix[i, j] = Console.ReadLine();
}
Console.WriteLine();
}
}
else { Console.WriteLine("Id does not exist"); }
}
static void deleteByid(string[,] matrix)
{
int pos = searchId(matrix);
if (pos != -1)
{
for (int i = pos; i < pos + 1; i++)
{
for (int j = 0; j < matrix.GetLength(1); j++)
{
matrix[i, j] = null;
}
}
}
else { Console.WriteLine("Id does not exist"); }
}
static void listData(string[,] matrix)
{
for (int i = 0; i < matrix.GetLength(0); i++)
{
for (int j = 0; j < matrix.GetLength(1); j++)
{
Console.Write($"\t{matrix[i, j]}\t");
}
Console.WriteLine("\n\t");
}
}
}
}
The first problem I can spot is in the menuAnimal method. Check what happens when you enter 0, for example by stepping through the code with debugger.
When user enters 0, the first do-while condition passes (as 0 is a number and is not smaller than 0 and not larger than 5), but in the following switch statement you do not have a case for 0, so the method stops executing and just redraws, because execution continues to menuReturn(animal); in MenuOptions.
The next main problem here is the menuReturn method. Observe that once you get in this method, you can never "escape". It always redraws the animals menu whatever happens and while(true) ensures that it will happened indefinitely. Because there is no break condition inside, it will just keep on going.
Different approach
I will suggest a different approach here, although there are many options you have, so you are free to use a different solution that suits you.
First get rid of the menuReturn method and put this "menu output loop within the menu methods themselves. In pseudo code this would be:
static void MenuMethod()
{
while (true)
{
userInput = read user input for example using do..while as in original code
goBack = false
switch (userInput)
{
case optionA:
doSomething();
goBack = true; //set go back to true if you want go up a level
break;
case optionSubmenu:
submenu(); //go to a submenu, which will start its own loop
//after submenu is closed (goBack = true), execution will return to this level
break;
}
if (goBack) return; //end execution of this menu
}
}
So briefly in your case it could look like this:
static void MenuOptions(string[,] animal)
{
while (true)
{
int userChoice;
do
{
Console.Clear();
Console.WriteLine("\nChoose one of the following options:\n");
Console.WriteLine("[ 1 ] Animals");
Console.WriteLine("[ 2 ] Clients");
Console.WriteLine("[ 0 ] Quit application\n");
} while (!int.TryParse(Console.ReadLine(), out userChoice) || userChoice < 0 || userChoice > 2);
Console.Clear();
switch (userChoice)
{
case 1:
menuAnimal(animal);
break;
case 2:
//menuClient(client);
break;
case 0:
Environment.Exit(0);
break;
default:
Console.WriteLine("Try again!!");
break;
}
}
}
Similar goes for animals menu:
static void MenuAnimal(string[,] animal)
{
while ( true )
{
int optAnimal;
do
{
Console.Clear();
Console.WriteLine("\nInsert one of the following options:\n");
Console.WriteLine("[ 1 ] Insert animal");
Console.WriteLine("[ 2 ] See animal");
Console.WriteLine("[ 3 ] Alter animal");
Console.WriteLine("[ 4 ] Erase animal");
Console.WriteLine("[ 5 ] List animals");
Console.WriteLine("[ 0 ] Return to main menu\n");
} while (!int.TryParse(Console.ReadLine(), out optAnimal) || optAnimal < 0 || optAnimal > 5);
Console.Clear();
bool goBack = false;
switch (optAnimal)
{
case 1:
insertData(animal);
break;
case 2:
visualizeByid(animal);
break;
case 3:
updateById(animal);
break;
case 4:
deleteByid(animal);
break;
case 5:
listData(animal);
break;
}
if ( goBack ) return;
}
}
I'm having some issues with my for loop. I've tried placing it in different areas and still, no luck. I'm working on a project that randomly changes the opacity of a rectangle (I have red, yellow, blue, and green). I got the project working so that it selects one color, raises opacity, waits, and then lowers opacity. However, I would like to repeat this and the loop will not.
Here is my code:
private int RandomNumber(int min, int max)
{
Random random = new Random();
return random.Next(min, max);
}
public void Start_Tapped_1(object sender, TappedRoutedEventArgs e)
{
loopthegame(5);
}
public void loopthegame(int amount)
{
for (int i = 0; i < amount; i++) {
startgame();
}
}
public async void startgame()
{
int randomcolor = RandomNumber(1, 8);
switch (randomcolor)
{
case 1:
Blue.Opacity = 1;
break;
case 2:
Red.Opacity = 1;
break;
case 3:
Yellow.Opacity = 1;
break;
case 4:
Green.Opacity = 1;
break;
case 5:
Blue.Opacity = 1;
break;
case 6:
Red.Opacity = 1;
break;
case 7:
Yellow.Opacity = 1;
break;
case 8:
Green.Opacity = 1;
break;
}
await Task.Delay(1000);
Blue.Opacity = 0.25;
Red.Opacity = 0.25;
Yellow.Opacity = 0.25;
Green.Opacity = 0.25;
}
It seems your async should be slightly updated:
public void loopthegame(int amount)
{
for (int i = 0; i < amount; i++) {
Task<int> t = startgame();
await t;
}
}
//...
public async Task<int> startgame()
{
int randomcolor = RandomNumber(1, 8);
switch (randomcolor)
{
case 1:
Blue.Opacity = 1;
break;
//...
case 8:
Green.Opacity = 1;
break;
}
await Task.Delay(1000);
Blue.Opacity = 0.25;
Red.Opacity = 0.25;
Yellow.Opacity = 0.25;
Green.Opacity = 0.25;
return randomcolor;
}
Well you need to do your async right (a slight modification):
public async void loopthegame(int amount)
{
for (int i = 0; i < amount; i++)
{
// this
await startgame();
}
}
Also:
public async Task startgame()
{
//...
}
Your problem is actually in your random number generator. When you create a random number generator with no seed (new Random()), it uses time as the seed. This runs fast enough that you're using the same seed every time, so RandomNumber returns the same number every time. Instead of creating a new Random every time, you should have one Random that you use multiple times. Create one in your constructor/main method, and use it repeatedly in your RandomNumber method.
This is easily tested with this bit of code:
for (int i = 0; i < 5; i++)
{
Random random = new Random();
Console.WriteLine(random.Next(1, 8));
}
Try it out, it will print the same value five times.
I'm trying to create a program for homework that displays a Tic-Tac-Toe board, and when the user clicks the button it displays a random number in all of the boxes. The number 1 = "X" and 0 = "O". I created 9 labels labeled "label1, label2...etc". Once the labels are full, I need to display who won, the letter X or O. I'm using arrays for this but am kinda of lost at this point. what do I need to do to display the random numbers into the labels. Here is the code I've written for the click event handler so far.
Random rand = new Random(2);
int click;
click = rand.Next(2);
const int ROWS = 3;
const int COLS = 3;
int[,] letters = new int[ROWS,COLS];
int ROW = ROWS;
int COL = COLS;
for (int row = 0; row < ROWS; ROW ++) {
for (int col = 0; col < COLS; COL ++) {
letters[row, col] = rand.Next(2);
int X = 1;//???
int O = 0;//???
label1.Text = [ROW,COL].ToString();//???
}
}
Here an attempt at an explanation:
first, you have the data to represent your problem:
const int ROWCOUNT = 3;
const int COLCOUNT = 3;
private int[,] letters = new int[ROWCOUNT,COLCOUNT];
Random rand = new Random(DateTime.Now.Ticks);
then you want to randomly fill that data:
private void randomize()
{
for( int row = 0; row < ROWCOUNT; row++ ){ //start with row=0, do row=row+1 until row no longer < ROWCOUNT
for( int col = 0; col < COLCOUNT; col++ ){
letters[row,col] = rand.nextInt(2);
}
}
}
finally, you want to display the array somewhere (in your case labels):
//These need to be added to a GridLayoutManager
private JLabel[,] labels = new JLabel[ROWCOUNT,COLCOUNT];
private void updateView(){
for( int row = 0; row < ROWCOUNT; row++ ){ //start with row=0, do row=row+1 until row no longer < ROWCOUNT
for( int col = 0; col < COLCOUNT; col++ ){
var current = letters[row,col];
var labelText = "O";
if( current > 0 )
labelText = "X";
labels[row,col].Text = labelText;
}
}
}
so, when the user clicks the button, you call:
randomize();
updateView();
hope it helps
from your comments, it seems setting the Label Text needs more explanation:
var labelText = "O";
if( current > 0 )
labelText = "X";
labels[row,col].Text = labelText;
maybe, i should have written it more like this:
String textForLabel = "O"; //0 represents O, 1 represents X
//test to see, if it really is a 0, not a 1
if( current != 0 ){
//oh, it is not a zero, therefore, set
textForLabel = "X";
}
JLabel labelAtRowAndCol = labels[row,col];
labelAtRowAndCol.Text = textForLabel;
I refuse to provide you the exact answer since you learning how to dot his is the entire point of this excerise.
Before I started the game I would randomly choose the first move: X or O.
I would then do the following:
1) I would place all the Labels into a collection.
2) I would randomly choose one of the Labels within the collection and change the Text property.
3) I would then remove the same Label from the collection
4) Rinse and Repeat.
You DO NOT need a two diminsional array for this.
In order to figure out the winner...I would keep track of the moves of each player. There is only a static number of winning moves in this game. Would be a simple task to determine if there were three X's in the top row or not.
#include<iostream>
#include<iomanip>
#include<set>
using namespace std;
char s[3][3] = {{'*','*','*'},{'*','*','*'},{'*','*','*'}};
void show(char os[3][3]);
int def[9];
void changeo(int n);
void changex(int n);
int stop();
set<int> cset;
int search (int n){
}
int main(){
int n; show(s);
int ss = 2;
cout<<endl;
while (stop()){
if (ss%2==0){
cout<<"player One(O) : enter n "; cin>>n;
if (!cset.count(n) && n<10){
cset.insert(n);
changeo(n);
show(s);
ss++;
}
else{
cout<<"invalid move"<<endl;
}
}
else{
cout<<"player Two(X) : enter n "; cin>>n;
if (!cset.count(n)&& n<10){
cset.insert(n);
changex(n);
show(s);
ss++;
}
}
}
cout<<"\nyou can see the winner"<<endl;
cout<<"your moves are "<<ss;
return 0;
}
void show(char s[3][3]){
cout<< setw(7)<< "1: " <<s[0][0]<<setw(5)<<"2: " <<s[0][1]<<setw(5)<<"3: " <<s[0][2]<<endl;
cout<< setw(7)<< "4: " <<s[1][0]<<setw(5)<<"5: " <<s[1][1]<<setw(5)<<"6: " <<s[1][2]<<endl;
cout<< setw(7)<< "7: " <<s[2][0]<<setw(5)<<"8: " <<s[2][1]<<setw(5)<<"9: " <<s[2][2]<<endl;
cout<<endl;
}
void changeo(int n){
switch(n){
case 1:
s[0][0] = 'O';
break;
case 2:
s[0][1] = 'O';
break;
case 3:
s[0][2] = 'O';
break;
case 4:
s[1][0] = 'O';
break;
case 5:
s[1][1] = 'O';
break;
case 6:
s[1][2] = 'O';
break;
case 7:
s[2][0] = 'O';
break;
case 8:
s[2][1] = 'O';
break;
case 9:
s[2][2] = 'O';
break;
}
}
void changex(int n){
switch(n){
case 1:
s[0][0] = 'X';
break;
case 2:
s[0][1] = 'X';
break;
case 3:
s[0][2] = 'X';
break;
case 4:
s[1][0] = 'X';
break;
case 5:
s[1][1] = 'X';
break;
case 6:
s[1][2] = 'X';
break;
case 7:
s[2][0] = 'X';
break;
case 8:
s[2][1] = 'X';
break;
case 9:
s[2][2] = 'X';
break;
}
}
int stop(){
int m=0;
for (int i=0; i<3; i++){
for (int j=0; j<3; j++){
if(s[i][j]=='*'){
m=1;
break;
}
}
}
return m;
}