public void mousePressed(MouseEvent e)
	{

		if (e.getButton() == 1)
		{
			for (Square[] a : squares)
			{
				for (Square s : a)
				{
					if (s.rect.contains(e.getPoint()) && s.piece == null)	// makes sure that a piece
																			// is
																			// not already there
					{
						// This creates a backup board which is a copy of the original board and if
						// a user can't play in a specific position, this wont allow them to, and
						// the boards position will
						// be reset to the backup board
						Piece[][] backup = new Piece[9][9];
						for (int i = 0; i < 9; i++)
							for (int j = 0; j < 9; j++)
								backup[i][j] = squares[i][j].piece;
						processGroups();
						int count = 0;
						for (GroupAi h : groups)
						{
							if (h.pieces.size() > 0 && h.pieces.toArray(new Piece[0])[0].team == current)
							{
								count++;
							}
						}
						s.piece = new Piece(current, s);
						processGroups();
						int count2 = 0;
						for (GroupAi h : groups)
						{
							if (h.pieces.size() > 0 && h.pieces.toArray(new Piece[0])[0].team == current)
							{
								count2++;
							}
						}
						capture();
						int count3 = 0;
						for (GroupAi h : groups)
						{
							if (h.pieces.size() > 0 && h.pieces.toArray(new Piece[0])[0].team == current)
							{
								count3++;
							}
						}
						// checks to see if a group is to be captured
						boolean atari = false;
						boolean koRule = false;
						for (int[][] i : ko)
						{
							int[][] copy = new int[9][9];
							for (int k = 0; k < squares.length; k++)
								for (int j = 0; j < squares[0].length; j++)
								{
									if (squares[k][j].piece == null)
									{
										copy[k][j] = -1;

									}
									else if (squares[k][j].piece.team)
									{
										copy[k][j] = 1;

									}
									else
										copy[k][j] = 0;
								}
							boolean equal = true;
							for (int j = 0; j < squares.length; j++)
							{
								for (int k = 0; k < squares[0].length; k++)
								{
									if (copy[j][k] != i[j][k])
										equal = false;
								}
							}
							if (equal)
							{
								koRule = true;
								break;
							}
						}
						if (count >= count2)
						{
							if (count2 != count3)
							{
								atari = true;
							}
						}
						else
						{
							if (count == count3)
							{
								atari = true;
							}
						}
						// changes color to other player.
						if (!atari && !koRule)
						{
							int[][] copy = new int[9][9];
							for (int i = 0; i < squares.length; i++)
								for (int j = 0; j < squares[0].length; j++)
								{
									if (squares[i][j].piece == null)
									{
										copy[i][j] = -1;

									}
									else if (squares[i][j].piece.team)
									{
										copy[i][j] = 1;

									}
									else
										copy[i][j] = 0;
								}
							ko.add(copy);

							if (current)
							{
								blackPass = false;
							}
							else
							{
								whitePass = false;
							}
							current = !current;
						}
						// If the group was in atari and a user played to which the group would be
						// killed(their own stones, not their opponents)
						// The board gets reset to its original position and the current player,
						// must play at a different position.
						else if (atari)
						{
							for (int i = 0; i < 9; i++)
							{
								for (int j = 0; j < 9; j++)
								{
									squares[i][j].piece = backup[i][j];
								}

							}
							JOptionPane.showMessageDialog(this, "You cant play here (see Atari Rule):\n You can't play anywhere which would allow you to kill a group of your own stones");
						}
						else if (koRule)
						{
							for (int i = 0; i < 9; i++)
							{
								for (int j = 0; j < 9; j++)
								{
									squares[i][j].piece = backup[i][j];
								}

							}
							JOptionPane.showMessageDialog(this, "You cant play here (see Ko Rule):\n You can't play anywhere which would result in a previous position of the board");
						}
					}
				}
			}
		}
		if (e.getButton() == 3)
		{
			if (current)
			{
				blackPass = true;
			}
			else
			{
				whitePass = true;
			}
			current = !current;
		}
	}