Could this be our future energy source?

One of the most pressing concerns for the survival and advancement of the human race is how to harness the Earth’s energy resources to provide enough power to continue running our machines and other devices. Clean renewable energy must surely be the future we have to strive for now. Whilst the following mini-essay may refer to a solution that is currently a long way off Onett in Year 9 speculates on the future of energy resources for the human race, looking not just on Earth but out in space!

The Dyson Sphere; (concrete noun) a megastructure encompassing a star and capturing a large proportion of its power output – the first step humans must take to expand into other planets.

The Dyson Sphere is a revolutionary idea, that was created in the twentieth century to explain how an extremely advanced civilisation will have enough energy to expand around the galaxy. It would give humans a virtually limitless quantity of energy, which will be the first step that gives us enough energy to take on projects that would otherwise be physically impossible, such as terraforming other planets in our solar system, establishing colonies of humans in space and gathering natural resources from the asteroid belt. Although this is technically hypothetical, I am confident that building one will not only be possible, but will be a vital step for our progress in the distant future.

As much as you and I want to see colonies of humans on Mars – we simply don’t have access to anywhere near the amount of energy required to do this on Earth; in fact, experts have predicted a cost upwards of twenty to forty billion US dollars to establish a small permanent settlement on the moon. In comparison, the distance between planet Earth and Mars on an average day is over 200 times the distance between planet Earth and the Moon; eventually, humans will be able to exploit 100% of all the energy available on Earth…then what happens – how will the humans progress?

Every second, the sun produces 3.86 x 1020 megawatts of energy – our Sun is one hundred quintillion times more powerful than the most efficient nuclear reactor on Earth. Although ideally, we would want a nice chunk of that, having only 0.1% of this would vastly increase the energy budget of the human race – if the world successfully harvested a thousandth of the sun’s energy, we would be able to expand into other planets in our solar system.

The actual Dyson Sphere is an incredibly simple design; a vast sea of light-reflecting objects orbiting the Sun. Traditional solar panels would be far too complex to use, so the majority of it would be huge mirrors held together with minimal metal, all of them orbiting around the Sun and focusing the light to an energy collecting station on Mercury. Mirrors – being so simple – could last for tens of thousands of years without human intervention. In terms of energy, we could send mining rovers to Mercury to use the metals in Mercury to build solar panels (for an energy collection point), mirrors (to orbit the sun) and more mining robots; because of exponential growth, the progress of creating a Dyson Sphere would vastly improve over time. Not only is Mercury so much closer – 28.5 million miles at the shortest and 58 million miles on average, compared to Earth’s 150 million miles distance – but Mercury also only has a little over one third of the gravity that Earth experiences; this makes it comparatively cheap to set up the creation of the Dyson Sphere on Mercury.

To conclude, wouldn’t it be an amazing idea to build a Dyson Sphere sometime in the future (I certainly think so)? Just like when humans discovered fire or electricity, this will be a colossal jump in the advancement of humankind. 

 

A fascinating insight into what the future of humankind could hold! Thank you Onett for sharing your vision with us. What do you think? Could harnessing solar energy in this way be the future? Let us know your thoughts in the comments. 

Ed Sheeran Artwork

We have received many wonderful pieces of artwork here at Insightful Imaginings and this next piece is no exception. The piece was submitted by Mia in Year 11 though it was created a few years ago. Using a light box and acrylic paint Mia was able to create this likeness of the singer along with his guitar and the resemblance is startling.

Thank you for sharing this with us Mia!

 

Mia Yr 11 Vale of York

Festive Textiles

As we wave goodbye to the festive period and 2018 it’s nice to look back on our memories of Christmas and winter. This piece produced by Rosie in year 9 does just that by capturing the very essence of a cold winter’s night. 

This fantastic piece of art took around 3 days to produce and began with painting the skyscape in inks. The project took place in the heat of summer in 2018 so took great mental effort to conjure the image of a cold winter sky! The stitching here is mainly machine embroidery using a range of different stitches to suggest a skyline of trees and to create texture in the branches and needles of the pines. The bobbly white fabric is used to depict a seasonally snowy landscape and a silk moon is just visible behind the cloud cover.

ozedf

 

 

Archaeologists Have Superpowers

On Thursday 15th November York ISSP held the first of its ISSP7-8 lectures held at the University of York. This series of inspirational lectures from high profile speakers is a termly event for years 7 & 8 and seeks to enthuse, educate and inspire the pupils. We were very lucky to have Alice Toso from the University of York deliver a talk entitled “What lies beneath our feet and other archaeological superpowers”. In Alice’s words ‘This talk will explore the superpowers that archaeologists have to discover the life of past societies. What lies beneath our feet and how do we get to see it? Today we will go for a round-the-world tour among famous archaeological sites to see how archaeologists have discovered them, studied them and what they tell us about life in the past.’

Alice has worked on collections from around the world and is a firm believer that archaeologists have superpowers and should help others gain a whole new perspective on the past. Everyone present had a wonderful opportunity to see through the eyes of an archaeologist and peer into the past.

Below we have an account of the lecture from a student at All Saints School:

All things Archaeology

On November 15th, lots of year seven and eight students from secondary schools in York
were invited to a lecture at the University of York. This was part of the ISSP7-8 lectures for children series. The topic of the lecture was “What lies beneath our feet and other
archaeological superpowers”, given by the archaeologist Alice Toso. At the start of the
lecture, we were divided into 6 groups, and we had to work together to answer questions
throughout the lecture.
The lecture focused on four case studies of early civilisations around the world, including York, Maccu Piccu, and went into detail about their cultures and the methods used to discover and preserve them. I learned numerous things including the fact that the strontium content in bones, can be used to work out where they lived. There was a quiz, about the case studies, and we all won the same amount of points, and
the lecture ended with a question and answer section, where numerous brilliant questions were asked, and clear answers given. Overall, it was a positive experience for the students and I hope to see more things like it in the future.

 

Thank you to Alice Toso and the University of York for such an amazing lecture and experience! 

Real or Fake Challenge

In the era of ‘fake news’ we are constantly reminded that we must challenge what we see and hear in order to gain a more complete view of the world. At Bootham School they have taken this to the next level and are challenging themselves to identify whether a scientific study is ‘Real’ or ‘Fake’. Students were tasked with creating a write-up of a real and a fake study to test their powers of deduction. They have now kindly agreed to share that with all of us so your task is quite simple, out of the two write-ups below can you tell whether they are ‘Real’ or ‘Fake’. Maybe both are real or neither of them are…you decide! Leave your answers in the comment section and we will let you know the answer in our next Real or Fake Challenge.

1. Do people with a stronger self-control experience less fatigue and bodily stress?

Cassandra Balder and her team spent five years studying and monitoring people with a strong self-control (overall about 5500 college students who were mostly women) and found that they do not get as fatigued as people with a lower self-control. This may be because they get an estimated 20 minutes extra sleep on average than others, which improves their energy levels. Also people with a stronger self-control experienced less daily stress, seemingly because they are more organized, which relived them of physical stress.

2. Do the number of toys a toddler has effect their creativeness?

Drew Dash at the University of Toronto studied 16 toddlers aged between 18 and 30 months, they were each given around 15 individual toys to play with for 30 minutes. The toys were then taken away and replaced with building blocks and paper with crayons. Another set of toddlers were also studied, however they were only given 4 toys to play with for the same amount of time. Dr Dash found out that the toddlers who only had 4 toys had built more creative structures with the building blocks and had drawn more creative drawings than the toddlers with 15 toys to play with. He concluded that surrounding your child with more toys than necessary will decrease their creativeness.

 

“Terrible Chess” – a program to find which chess colour is best

Take a look at this impressive piece of programming by Sam in Year 11. It really gives you an insight into the complexities of computer science. 

“Terrible chess” is a program I wrote that created almost the worst chess AI that could ever exist. This isn’t hyperbole – the AI makes all decisions at random and has no concept of preservation of the king. The only AI that could be worse than it would lose deliberately.

So why would I spend hours of my time creating this AI when I could be doing better things with my time?

Simply to make it play against itself.

These two AI would have a perfectly equal skill level. Admittedly, the skill level was 0, but it still allowed me to do my experiment.

What was my experiment? I wanted to find out if the old saying was correct; “white begins and black wins.” I wanted to find out which colour gave you an edge. Along the way, I also found out an average game length, along with some strange glitches, some of which I still have not removed because I have no idea what causes them.

I coded in python, for no reason other than that it is the only programming language I know in depth. The program is long, 782 lines long, the longest program I have ever created.

5000 games were played. While this is not a very large sample space, I feel this is large enough. 250,449 turns, where one turn was a white move, then a black move, occurred, an average of just over 50 per game. This average possibly should be higher, but most long games crashed the program.

The longest game was 200 moves, though, again, it could be higher.

The shortest was 1.

I have tried to explain how this could be possible, but I am forced to admit it must be one of the strange glitches I mentioned earlier. Even using my arbitrary “turns” that would allow three moves to have happened there is no way for a king to have been taken that early. Therefore, I believe that this occurred due to chance, and the subprogram for finding stalemates did not find a movable piece, just due to random chance.

Finally, I reach the results of the games. These were the original aim of this program, the only reason I spent hours of my lunch breaks constantly coding, testing, being confused at why the program crashed when I tried to get it to do 20 games at a time, and fixing.

Before these results, however, I must mention that this is not an accurate test. This program has many faults, such as pawns not being able to take pieces while on the edge, or there being no form of check and just relying on the king being taken. However, I believe that this is still accurate enough to discover which colour is best.

So, the results; in 5000 games there were…

111 draws…

2330 white wins and…

2559 black wins.

In percentages, that’s 2.22% draw, 46.6% white and 51.18% black. Black wins almost 10% more games than white does.

So, if you want an edge on someone while playing chess, play black. If you have an even skill level, chances are you will win 10% more than them.

Here is the fantastic coding!

from random import *
def boardreset():
    board = [["bR","bK","bB","bQ","BK","bB","bK","bR"],
             ["bP","bP","bP","bP","bP","bP","bP","bP"],
             ["__","__","__","__","__","__","__","__"],
             ["__","__","__","__","__","__","__","__"],
             ["__","__","__","__","__","__","__","__"],
             ["__","__","__","__","__","__","__","__"],
             ["wP","wP","wP","wP","wP","wP","wP","wP"],
             ["wR","wK","wB","wQ","WK","wB","wK","wR"]]

drawmoves = 0
totalmoves = 0
board = [["bR","bK","bB","bQ","BK","bB","bK","bR"],
         ["bP","bP","bP","bP","bP","bP","bP","bP"],
         ["__","__","__","__","__","__","__","__"],
         ["__","__","__","__","__","__","__","__"],
         ["__","__","__","__","__","__","__","__"],
         ["__","__","__","__","__","__","__","__"],
         ["wP","wP","wP","wP","wP","wP","wP","wP"],
         ["wR","wK","wB","wQ","WK","wB","wK","wR"]]
def printboard():
    for i in range(0,8):
        print(board[i])
def move(x1,y1,x2,y2):              #note - coordinate system is reversed (y,x) and origin is top left. no clear way to change. 
    piece = board[y1][x1]
    if board[y2][x2] != "__":
        global drawmoves
        drawmoves = 0
    board[y1][x1] = "__"
    board[y2][x2] = piece
def pawn(x,y,colour,testing):
    if colour == "black":
        if x - 1 > -1 and x + 1 < 8 and y + 1 < 8:#change so piece on edge can take piece
            if board[y + 1][x - 1][0] == "w" or board[y + 1][x - 1][0] == "W" or board[y + 1][x + 1][0] == "w" or board[y + 1][x + 1][0] == "W":
                if testing == True:
                    return True
                choosing = True
                while choosing == True:
                    random = randint(0,3)
                    if random == 3 and (board[y + 1][x - 1][0] == "w" or board[y + 1][x - 1][0] == "W"):
                        move(x, y, x - 1, y + 1)
                        choosing = False
                    elif random == 2 and (board[y + 1][x + 1][0] == "w" or board[y + 1][x + 1][0] == "W"):
                        move(x, y, x + 1, y + 1)
                        choosing = False
                    elif random == 1 and board[y + 1][x] == "__":
                        move(x, y, x, y + 1)
                        choosing = False
                    elif random == 0 and y == 1 and board[y + 2][x] == "__" and board[y + 1][x] == "__":
                            move(x, y, x, y + 2)
                            choosing = False
                    else:
                        choosing = True
        elif y + 1 < 8:
            if board[y + 1][x] == "__":
                if testing == True:
                    return True
                elif y == 1 and board[y + 2][x] == "__":
                    random = randint(0,1)
                    if random == 1:
                        move(x, y, x, y + 2)
                    else:
                        move(x, y, x, y + 1)
                else:
                    move(x, y, x, y + 1)
        if y == 7:
            pieces = ["bR", "bB", "bK", "bQ"]
            board[y][x] = pieces[randint(0,3)]
    else:
        if x - 1 > -1 and x + 1 < 8 and y - 1 > -1:
            if board[y - 1][x - 1][0] == "b" or board[y - 1][x - 1][0] == "B" or board[y - 1][x + 1][0] == "b" or board[y - 1][x + 1][0] == "B":
                if testing == True:
                    return True
                choosing = True
                while choosing == True:
                    random = randint(0,3)
                    if random == 2 and (board[y - 1][x - 1][0] == "b" or board[y - 1][x - 1][0] == "B"):
                        move(x, y, x - 1, y - 1)
                        choosing = False
                    elif random == 1 and (board[y - 1][x + 1][0] == "b" or board[y - 1][x + 1][0] == "B"):
                        move(x, y, x + 1, y - 1)
                        choosing = False
                    elif random == 0 and board[y - 1][x] == "__":
                        move(x, y, x, y - 1)
                        choosing = False
                    elif random == 0 and y == 6 and board[y - 2][x] == "__" and board[y - 1][x] == "__":
                        move(x, y, x, y - 2)
                        choosing = False
                    else:
                        choosing = True
            elif y - 1 > -1:
                if board[y - 1][x] == "__":
                    if testing == True:
                        return True
                    elif y == 6 and board[y - 2][x] == "__":
                        random = randint(0,1)
                        if random == 1:
                            move(x, y, x, y - 2)
                        else:
                            move(x, y, x, y - 1)
                    else:
                        move(x, y, x, y - 1)
        if y == 0:
            pieces = ["wR", "wB", "wK", "wQ"]
            board[y][x] = pieces[randint(0,3)]
    if testing == True:
        return False
    global drawmoves
    drawmoves = 0
def knight(x,y,colour,testing):
    choosing = True
    timestried = 0
    while choosing == True:
        random = randint(0,7)
        if random == 0:
            if (y-2 > -1 and x - 1 > -1):
                if(colour == "black" and board[y-2][x-1][0] != "b" and board[y-2][x-1][0] != "B") or (colour == "white" and board[y-2][x-1][0] != "w" and board[y-2][x-1][0] != "W"):
                    if testing == True:
                        return True
                    else:
                        move(x,y,x-1,y-2)
                        choosing = False
                else:
                    timestried += 1
            else:
                timestried += 1
        elif random == 1:
            if (y-2 > -1 and x + 1 < 8):
                if(colour == "black" and board[y-2][x+1][0] != "b" and board[y-2][x+1][0] != "B") or (colour == "white" and board[y-2][x+1][0] != "w" and board[y-2][x+1][0] != "W"):
                    if testing == True:
                        return True
                    else:
                        move(x,y,x+1,y-2)
                        choosing = False
                else:
                    timestried += 1
            else:
                timestried += 1
        elif random == 2:
            if (y-1 > -1 and x + 2 < 8):
                if(colour == "black" and board[y-1][x+2][0] != "b" and board[y-1][x+2][0] != "B") or (colour == "white" and board[y-1][x+2][0] != "w" and board[y-1][x+2][0] != "W"):
                    if testing == True:
                        return True
                    else:
                        move(x,y,x+2,y-1)
                        choosing = False
                else:
                    timestried += 1
            else:
                timestried += 1
        elif random == 3:
            if (y+1 < 8 and x + 2 < 8):
                if(colour == "black" and board[y+1][x+2][0] != "b" and board[y+1][x+2][0] != "B") or (colour == "white" and board[y+1][x+2][0] != "w" and board[y+1][x+2][0] != "W"):
                    if testing == True:
                        return True
                    else:
                        move(x,y,x+2,y+1)
                        choosing = False
                else:
                    timestried += 1
            else:
                timestried += 1
        elif random == 4:
            if (y+2 < 8 and x + 1 < 8):
                if(colour == "black" and board[y+2][x+1][0] != "b" and board[y+2][x+1][0] != "B") or (colour == "white" and board[y+2][x+1][0] != "w" and board[y+2][x+1][0] != "W"):
                    if testing == True:
                        return True
                    else:
                        move(x,y,x+1,y+2)
                        choosing = False
                else:
                    timestried += 1
            else:
                timestried += 1
        elif random == 5:
            if (y+2 < 8 and x - 1 > -1):
                if(colour == "black" and board[y+2][x-1][0] != "b" and board[y+2][x-1][0] != "B") or (colour == "white" and board[y+2][x-1][0] != "w" and board[y+2][x-1][0] != "W"):
                    if testing == True:
                        return True
                    else:
                        move(x,y,x-1,y+2)
                        choosing = False
                else:
                    timestried += 1
            else:
                timestried += 1
        elif random == 6:
            if (y+1 < 8 and x - 2 > -1):
                if(colour == "black" and board[y+1][x-2][0] != "b" and board[y+1][x-2][0] != "B") or (colour == "white" and board[y+1][x-2][0] != "w" and board[y+1][x-2][0] != "W"):
                    if testing == True:
                        return True
                    else:
                        move(x,y,x-2,y+1)
                        choosing = False
                else:
                    timestried += 1
            else:
                timestried += 1
        elif random == 7:
            if (y-1 > -1 and x - 2 > -1):
                if(colour == "black" and board[y-1][x-2][0] != "b" and board[y-1][x-2][0] != "B") or (colour == "white" and board[y-1][x-2][0] != "w" and board[y-1][x-2][0] != "W"):
                    if testing == True:
                        return True
                    else:
                        move(x,y,x-2,y-1)
                        choosing = False
                else:
                    timestried += 1
            else:
                timestried += 1
        if timestried >= 20 and testing == True:
            return False
def bishop(x,y,colour,testing):
    choosing = True
    timestried = 0
    while choosing == True:
        random = randint(0,3)
        if random == 0 and (y - 1 > -1 and x + 1 < 8):
            if y < 7 - x:
                smallestcoord = y
            else:
                smallestcoord = 7 - x
            random = randint(1, smallestcoord)
            moving = True
            for i in range(1, random + 1):
                if moving == True and((colour == "black" and board[y-i][x+i][0] != "b" and board[y-i][x+i][0] != "B") or (colour == "white" and board[y-i][x+i][0] != "w" and board[y-i][x+i][0] != "W")):
                    if testing == True:
                        return True
                    elif (colour == "black" and (board[y-i][x+i][0] == "w" or board[y-i][x+i][0] == "W")) or (colour == "white" and (board[y-i][x+i][0] == "b" or board[y-i][x+i][0] == "B")):
                        move(x+(i-1),y-(i-1),x+i,y-i)
                        moving = False
                    else:
                        move(x+(i-1),y-(i-1),x+i,y-i)
                    choosing = False  
                else:
                    moving = False
                if i == 1:
                        timestried += 1
        if random == 1 and (y + 1 < 8 and x + 1 < 8):
            if y > x:
                smallestcoord = 7 - y
            else:
                smallestcoord = 7 - x
            random = randint(1, smallestcoord)
            moving = True
            for i in range(1, random + 1):
                if moving == True and((colour == "black" and board[y+i][x+i][0] != "b" and board[y+i][x+i][0] != "B") or (colour == "white" and board[y+i][x+i][0] != "w" and board[y+i][x+i][0] != "W")):
                    if testing == True:
                        return True
                    elif (colour == "black" and (board[y+i][x+i][0] == "w" or board[y+i][x+i][0] == "W")) or (colour == "white" and (board[y+i][x+i][0] == "b" or board[y+i][x+i][0] == "B")):
                        move(x+(i-1),y+(i-1),x+i,y+i)
                        moving = False
                    else:
                        move(x+(i-1),y+(i-1),x+i,y+i)
                    choosing = False
                else:
                    moving = False
                    if i == 1:
                        timestried += 1
        if random == 2 and (x - 1 > -1 and y + 1 < 8):
            if x < 7 - y:
                smallestcoord = x
            else:
                smallestcoord = 7 - y
            random = randint(1, smallestcoord)
            moving = True
            for i in range(1, random + 1):
                if moving == True and((colour == "black" and board[y+i][x-i][0] != "b" and board[y+i][x-i][0] != "B") or (colour == "white" and board[y+i][x-i][0] != "w" and board[y+i][x-i][0] != "W")):
                    if testing == True:
                        return True
                    elif (colour == "black" and (board[y+i][x-i][0] == "w" or board[y+i][x-i][0] == "W")) or (colour == "white" and (board[y+i][x-i][0] == "b" or board[y+i][x-i][0] == "B")):
                        move(x-(i-1),y+(i-1),x-i,y+i)
                        moving = False
                    else:
                        move(x-(i-1),y+(i-1),x-i,y+i)
                    choosing = False
                else:
                    moving = False
                    if i == 1:
                        timestried += 1
        elif random == 3 and (y - 1 > -1 and x - 1 > -1):
            if y < x:
                smallestcoord = y
            else:
                smallestcoord = x
            random = randint(1, smallestcoord)
            moving = True
            for i in range(1, random + 1):
                if moving == True and((colour == "black" and board[y-i][x-i][0] != "b" and board[y-i][x-i][0] != "B") or (colour == "white" and board[y-i][x-i][0] != "w" and board[y-i][x-i][0] != "W")):
                    if testing == True:
                        return True
                    elif (colour == "black" and (board[y-i][x-i][0] == "w" or board[y-i][x-i][0] == "W")) or (colour == "white" and (board[y-i][x-i][0] == "b" and board[y-i][x-i][0] == "B")):
                        move(x-(i-1),y-(i-1),x-i,y-i)
                        moving = False
                    else:
                        move(x-(i-1),y-(i-1),x-i,y-i)
                    choosing = False
                else:
                    moving = False
                    if i == 1:
                        timestried += 1
        else:
            timestried += 1
        if timestried >= 10 and testing == True:
            return False
def rook(x,y,colour,testing):
    choosing = True
    timestried = 0
    while choosing == True:
        random = randint(0,3)
        if random == 0 and (y - 1 > -1):
            random = randint(1, y)
            moving = True
            for i in range(1, random + 1):
                if moving == True and((colour == "black" and board[y-i][x][0] != "b" and board[y-i][x][0] != "B") or (colour == "white" and board[y-i][x][0] != "w" and board[y-i][x][0] != "W")):
                    if testing == True:
                        return True
                    elif (colour == "black" and (board[y-i][x][0] == "w" or board[y-i][x][0] == "W")) or (colour == "white" and (board[y-i][x][0] == "b" or board[y-i][x][0] == "B")):
                        move(x,y-(i-1),x,y-i)
                        moving = False
                    else:
                        move(x,y-(i-1),x,y-i)
                    choosing = False
                else:
                    moving = False
                if i == 1:
                        timestried += 1
        if random == 1 and (x + 1 < 8):
            random = randint(1, 7 - x)
            moving = True
            for i in range(1, random + 1):
                if moving == True and((colour == "black" and board[y][x+i][0] != "b" and board[y][x+i][0] != "B") or (colour == "white" and board[y][x+i][0] != "w" and board[y][x+i][0] != "W")):
                    if testing == True:
                        return True
                    elif (colour == "black" and (board[y][x+i][0] == "w" or board[y][x+i][0] == "W")) or (colour == "white" and (board[y][x+i][0] == "b" or board[y][x+i][0] == "B")):
                        move(x+(i-1),y,x+i,y)
                        moving = False
                    else:
                        move(x+(i-1),y,x+i,y)
                    choosing = False
                else:
                    moving = False
                    if i == 1:
                        timestried += 1
        if random == 2 and (y + 1 < 8):
            random = randint(1, 7 - y)
            moving = True
            for i in range(1, random + 1):
                if moving == True and((colour == "black" and board[y+i][x][0] != "b" and board[y+i][x][0] != "B") or (colour == "white" and board[y+i][x][0] != "w" and board[y+i][x][0] != "W")):
                    if testing == True:
                        return True
                    elif (colour == "black" and (board[y+i][x][0] == "w" or board[y+i][x][0] == "W")) or (colour == "white" and (board[y+i][x][0] == "b" or board[y+i][x][0] == "B")):
                        move(x,y+(i-1),x,y+i)
                        moving = False
                    else:
                        move(x,y+(i-1),x,y+i)
                    choosing = False
                else:
                    moving = False
                    if i == 1:
                        timestried += 1
        elif random == 3 and (x - 1 > -1):
            random = randint(1, x)
            moving = True
            for i in range(1, random + 1):
                if moving == True and((colour == "black" and board[y][x-i][0] != "b" and board[y][x-i][0] != "B") or (colour == "white" and board[y][x-i][0] != "w" and board[y][x-i][0] != "W")):
                    if testing == True:
                        return True
                    elif (colour == "black" and (board[y][x-i][0] == "w" or board[y][x-i][0] == "W")) or (colour == "white" and (board[y][x-i][0] == "b" or board[y][x-i][0] == "B")):
                        move(x-(i-1),y,x-i,y)
                        moving = False
                    else:
                        move(x-(i-1),y,x-i,y)
                    choosing = False
                else:
                    moving = False
                    if i == 1:
                        timestried += 1
        else:
            timestried += 1
        if timestried >= 10 and testing == True:
            return False
def king(x,y,colour,testing):
    choosing = True
    timestried = 0
    while choosing == True:
        random = randint(0,7)
        if random == 0 and (y - 1 > -1):
            if ((colour == "black" and board[y-1][x][0] != "b" and board[y-1][x][0] != "B") or (colour == "white" and board[y-1][x][0] != "w" and board[y-1][x][0] != "W")):
                if testing == True:
                    return True
                else:
                    move(x,y,x,y-1)
                choosing = False
            else:
                timestried += 1
        if random == 1 and (x + 1 < 8):
            if ((colour == "black" and board[y][x+1][0] != "b" and board[y][x+1][0] != "B") or (colour == "white" and board[y][x+1][0] != "w" and board[y][x+1][0] != "W")):
                if testing == True:
                    return True
                else:
                    move(x,y,x+1,y)
                    choosing = False
            else:
                timestried += 1
        if random == 2 and (y + 1 < 8):
            if ((colour == "black" and board[y+1][x][0] != "b" and board[y+1][x][0] != "B") or (colour == "white" and board[y+1][x][0] != "w" and board[y+1][x][0] != "W")):
                if testing == True:
                    return True
                else:
                    move(x,y,x,y+1)
                choosing = False
            else:
                timestried += 1
        elif random == 3 and (x - 1 > -1):
            if ((colour == "black" and board[y][x-1][0] != "b" and board[y][x-1][0] != "B") or (colour == "white" and board[y][x-1][0] != "w" and board[y][x-1][0] != "W")):
                if testing == True:
                    return True
                else:
                    move(x,y,x-1,y)
                choosing = False
            else:
                timestried += 1
        if random == 4 and (y - 1 > -1 and x + 1 < 8):
            if ((colour == "black" and board[y-1][x+1][0] != "b" and board[y-1][x+1][0] != "B") or (colour == "white" and board[y-1][x+1][0] != "w" and board[y-1][x+1][0] != "W")):
                if testing == True:
                    return True
                else:
                    move(x,y,x+1,y-1)
                choosing = False  
            else:
                timestried += 1
        if random == 5 and (y + 1 < 8 and x + 1 < 8):
            if ((colour == "black" and board[y+1][x+1][0] != "b" and board[y+1][x+1][0] != "B") or (colour == "white" and board[y+1][x+1][0] != "w" and board[y+1][x+1][0] != "W")):
                if testing == True:
                    return True
                else:
                    move(x,y,x+1,y+1)
                choosing = False
            else:
                timestried += 1
        if random == 6 and (x - 1 > -1 and y + 1 < 8):
            if ((colour == "black" and board[y+1][x-1][0] != "b" and board[y+1][x-1][0] != "B") or (colour == "white" and board[y+1][x-1][0] != "w" and board[y+1][x-1][0] != "W")):
                if testing == True:
                    return True
                else:
                    move(x,y,x-1,y+1)
                choosing = False
            else:
                timestried += 1
        elif random == 7 and (y - 1 > -1 and x - 1 > -1):
            if (colour == "black" and board[y-1][x-1][0] != "b" and board[y-1][x-1][0] != "B") or (colour == "white" and board[y-1][x-1][0] != "w" and board[y-1][x-1][0] != "W"):
                if testing == True:
                    return True
                else:
                    move(x,y,x-1,y-1)
                choosing = False
            else:
                timestried += 1
        else:
            timestried += 1
        if timestried >= 20 and testing == True:
            return False
def queen(x,y,colour,testing):
    choosing = True
    timestried = 0
    while choosing == True:
        random = randint(0,7)
        if random == 0 and (y - 1 > -1):
            random = randint(1, y)
            moving = True
            for i in range(1, random + 1):
                if moving == True and((colour == "black" and board[y-i][x][0] != "b" and board[y-i][x][0] != "B") or (colour == "white" and board[y-i][x][0] != "w" and board[y-i][x][0] != "W")):
                    if testing == True:
                        return True
                    elif (colour == "black" and (board[y-i][x][0] == "w" or board[y-i][x][0] == "W")) or (colour == "white" and (board[y-i][x][0] == "b" or board[y-i][x][0] == "B")):
                        move(x,y-(i-1),x,y-i)
                        moving = False
                    else:
                        move(x,y-(i-1),x,y-i)
                    choosing = False
                else:
                    moving = False
                if i == 1:
                        timestried += 1
        if random == 1 and (x + 1 < 8):
            random = randint(1, 7 - x)
            moving = True
            for i in range(1, random + 1):
                if moving == True and((colour == "black" and board[y][x+i][0] != "b" and board[y][x+i][0] != "B") or (colour == "white" and board[y][x+i][0] != "w" and board[y][x+i][0] != "W")):
                    if testing == True:
                        return True
                    elif (colour == "black" and (board[y][x+i][0] == "w" or board[y][x+i][0] == "W")) or (colour == "white" and (board[y][x+i][0] == "b" or board[y][x+i][0] == "B")):
                        move(x+(i-1),y,x+i,y)
                        moving = False
                    else:
                        move(x+(i-1),y,x+i,y)
                    choosing = False
                else:
                    moving = False
                    if i == 1:
                        timestried += 1
        if random == 2 and (y + 1 < 8):
            random = randint(1, 7 - y)
            moving = True
            for i in range(1, random + 1):
                if moving == True and((colour == "black" and board[y+i][x][0] != "b" and board[y+i][x][0] != "B") or (colour == "white" and board[y+i][x][0] != "w" and board[y+i][x][0] != "W")):
                    if testing == True:
                        return True
                    elif (colour == "black" and (board[y+i][x][0] == "w" or board[y+i][x][0] == "W")) or (colour == "white" and (board[y+i][x][0] == "b" or board[y+i][x][0] == "B")):
                        move(x,y+(i-1),x,y+i)
                        moving = False
                    else:
                        move(x,y+(i-1),x,y+i)
                    choosing = False
                else:
                    moving = False
                    if i == 1:
                        timestried += 1
        elif random == 3 and (x - 1 > -1):
            random = randint(1, x)
            moving = True
            for i in range(1, random + 1):
                if moving == True and((colour == "black" and board[y][x-i][0] != "b" and board[y][x-i][0] != "B") or (colour == "white" and board[y][x-i][0] != "w" and board[y][x-i][0] != "W")):
                    if testing == True:
                        return True
                    elif (colour == "black" and (board[y][x-i][0] == "w" or board[y][x-i][0] == "W")) or (colour == "white" and (board[y][x-i][0] == "b" or board[y][x-i][0] == "B")):
                        move(x-(i-1),y,x-i,y)
                        moving = False
                    else:
                        move(x-(i-1),y,x-i,y)
                    choosing = False
                else:
                    moving = False
                    if i == 1:
                        timestried += 1
        if random == 4 and (y - 1 > -1 and x + 1 < 8):
            if y < 7 - x:
                smallestcoord = y
            else:
                smallestcoord = 7 - x
            random = randint(1, smallestcoord)
            moving = True
            for i in range(1, random + 1):
                if moving == True and((colour == "black" and board[y-i][x+i][0] != "b" and board[y-i][x+i][0] != "B") or (colour == "white" and board[y-i][x+i][0] != "w" and board[y-i][x+i][0] != "W")):
                    if testing == True:
                        return True
                    elif (colour == "black" and (board[y-i][x+i][0] == "w" or board[y-i][x+i][0] == "W")) or (colour == "white" and (board[y-i][x+i][0] == "b" or board[y-i][x+i][0] == "B")):
                        move(x+(i-1),y-(i-1),x+i,y-i)
                        moving = False
                    else:
                        move(x+(i-1),y-(i-1),x+i,y-i)
                    choosing = False  
                else:
                    moving = False
                if i == 1:
                        timestried += 1
        if random == 5 and (y + 1 < 8 and x + 1 < 8):
            if y > x:
                smallestcoord = 7 - y
            else:
                smallestcoord = 7 - x
            random = randint(1, smallestcoord)
            moving = True
            for i in range(1, random + 1):
                if moving == True and((colour == "black" and board[y+i][x+i][0] != "b" and board[y+i][x+i][0] != "B") or (colour == "white" and board[y+i][x+i][0] != "w" and board[y+i][x+i][0] != "W")):
                    if testing == True:
                        return True
                    elif (colour == "black" and (board[y+i][x+i][0] == "w" or board[y+i][x+i][0] == "W")) or (colour == "white" and (board[y+i][x+i][0] == "b" or board[y+i][x+i][0] == "B")):
                        move(x+(i-1),y+(i-1),x+i,y+i)
                        moving = False
                    else:
                        move(x+(i-1),y+(i-1),x+i,y+i)
                    choosing = False
                else:
                    moving = False
                    if i == 1:
                        timestried += 1
        if random == 6 and (x - 1 > -1 and y + 1 < 8):
            if x < 7 - y:
                smallestcoord = x
            else:
                smallestcoord = 7 - y
            random = randint(1, smallestcoord)
            moving = True
            for i in range(1, random + 1):
                if moving == True and((colour == "black" and board[y+i][x-i][0] != "b" and board[y+i][x-i][0] != "B") or (colour == "white" and board[y+i][x-i][0] != "w" and board[y+i][x-i][0] != "W")):
                    if testing == True:
                        return True
                    elif (colour == "black" and (board[y+i][x-i][0] == "w" or board[y+i][x-i][0] == "W")) or (colour == "white" and (board[y+i][x-i][0] == "b" or board[y+i][x-i][0] == "B")):
                        move(x-(i-1),y+(i-1),x-i,y+i)
                        moving = False
                    else:
                        move(x-(i-1),y+(i-1),x-i,y+i)
                    choosing = False
                else:
                    moving = False
                    if i == 1:
                        timestried += 1
        elif random == 7 and (y - 1 > -1 and x - 1 > -1):
            if y < x:
                smallestcoord = y
            else:
                smallestcoord = x
            random = randint(1, smallestcoord)
            moving = True
            for i in range(1, random + 1):
                if moving == True and((colour == "black" and board[y-i][x-i][0] != "b" and board[y-i][x-i][0] != "B") or (colour == "white" and board[y-i][x-i][0] != "w" and board[y-i][x-i][0] != "W")):
                    if testing == True:
                        return True
                    elif (colour == "black" and (board[y-i][x-i][0] == "w" or board[y-i][x-i][0] == "W")) or (colour == "white" and (board[y-i][x-i][0] == "b" and board[y-i][x-i][0] == "B")):
                        move(x-(i-1),y-(i-1),x-i,y-i)
                        moving = False
                    else:
                        move(x-(i-1),y-(i-1),x-i,y-i)
                    choosing = False
                else:
                    moving = False
                    if i == 1:
                        timestried += 1
        else:
            timestried += 1
        if timestried >= 20 and testing == True:
            return False
def test(x,y,colour):
    piece = board[y][x]
    if piece == "bP" or piece == "wP":
        return pawn(x,y,colour,True)
    elif piece == "bB" or piece == "wB":
        return bishop(x,y,colour,True)
    elif piece == "bK" or piece == "wK":
        return knight(x,y,colour,True)
    elif piece == "bR" or piece == "wR":
        return rook(x,y,colour,True)
    elif piece == "bQ" or piece == "wQ":
        return queen(x,y,colour,True)
    elif piece == "BK" or piece == "WK":
        return king(x,y,colour,True)
def movepiece(x,y,colour):
    piece = board[y][x]
    if piece == "bP" or piece == "wP":
        pawn(x,y,colour,False)
    elif piece == "bB" or piece == "wB":
        bishop(x,y,colour,False)
    elif piece == "bK" or piece == "wK":
        knight(x,y,colour,False)
    elif piece == "bR" or piece == "wR":
        rook(x,y,colour,False)
    elif piece == "bQ" or piece == "wQ":
        queen(x,y,colour,False)
    elif piece == "BK" or piece == "WK":
        king(x,y,colour,False)
def turn(colour):
    choosing = True
    stalemoves = 0
    while choosing == True:
        x = randint(0,7)
        y = randint(0,7)
        pieceColour = board[y][x][0]
        if (colour == "white" and (pieceColour == "w" or pieceColour == "W")) or (colour == "black" and (pieceColour == "b" or pieceColour == "B")):
            if test(x,y,colour) == True:
                choosing = False
                movepiece(x,y,colour)
                return True
            else:
                stalemoves += 1
        if stalemoves == 30:
            return False
def turnspair():
    if turn("white") == True:
        if turn("black") == True:
            global drawmoves
            drawmoves += 1
            return True
        else:
            return False
    else:
        return False
def onboard(piece):
    for i in range(0,8):
        for j in range(0,8):
            if board[j][i] == piece:
                return True
    return False
shortest = 1000000000000
longest = 0
gamemoves = 0
def game():
    playing = True
    global gamemoves 
    gamemoves = 0
    while playing == True:
        if turnspair() == True:
            global totalmoves
            totalmoves += 1
            gamemoves += 1
            if ((drawmoves >= 50) or (onboard("BK") == False) or (onboard("WK") == False)):
                playing = False
        else:
            return("DRAW")
    if drawmoves >= 50:
        return("DRAW")
    elif onboard("BK") == False:
        return("WHITE WINS")
    elif onboard("WK") == False:
        return("BLACK WINS")
    else:
        return("urmmmmmmmmm")
times = int(input("how many games?"))
whitewins = 0
blackwins = 0
draws = 0
for i in range(0,times):
    board = [["bR","bK","bB","bQ","BK","bB","bK","bR"],
             ["bP","bP","bP","bP","bP","bP","bP","bP"],
             ["__","__","__","__","__","__","__","__"],
             ["__","__","__","__","__","__","__","__"],
             ["__","__","__","__","__","__","__","__"],
             ["__","__","__","__","__","__","__","__"],
             ["wP","wP","wP","wP","wP","wP","wP","wP"],
             ["wR","wK","wB","wQ","WK","wB","wK","wR"]]
    drawmoves = 0
    result = game()
    if gamemoves > longest:
        longest = gamemoves
    if gamemoves < shortest:
        shortest = gamemoves
    print("Games done: " + str(i + 1))
    if result == "DRAW":
        draws += 1
    elif result == "WHITE WINS":
        whitewins += 1
    elif result == "BLACK WINS":
        blackwins += 1
import csv
def read(filename):                        #subprogramme for reading from a file
    data = []
    with open(filename) as csvfile:
        readCSV = csv.reader(csvfile, delimiter=",")
        for row in readCSV:
            data.append(row)
    return data
def write(filename, data):                 #subprogramme for writing to a file
    with open(filename, "w", newline="") as csvfile:
        writeCSV = csv.writer(csvfile)
        for item in range(len(data)):
            writeCSV.writerow(data[item])
def add(filename, data):                   #subprogramme for adding to a file. Uses read and write subprogrammes
    file = read(filename)
    for item in range(len(data)):
        file.append(data[item])
    write(filename, file)
print("Black won " + str(blackwins) + " times, white won " + str(whitewins) + " times")
print("There were " + str(draws) + " draws.")
chessTotals = read("chessTotals.csv")
totalblack = int(chessTotals[0][0])
totalblack += blackwins
totalwhite = int(chessTotals[0][1])
totalwhite += whitewins
totaldraw = int(chessTotals[0][2])
totaldraw += draws
overallmove = int(chessTotals[0][3])
overallmove += totalmoves
totaltimes = int(chessTotals[0][4])
totaltimes += times
shortesttotal = int(chessTotals[0][5])
if shortest < shortesttotal:
    shortesttotal = shortest
longesttotal = int(chessTotals[0][6])
if longest > longesttotal:
    longesttotal = longest
blackpercent = (totalblack / totaltimes) * 100
whitepercent = (totalwhite / totaltimes) * 100
movesaverage = (overallmove / totaltimes)
drawpercent = (totaldraw / totaltimes) * 100
print("Black won " + str(blackpercent) + "% of the time. White won " + str(whitepercent) + "% of the time. It is a draw " + str(drawpercent) + "% of the time")
print("There were " + str(overallmove) + " moves, an average of " + str(movesaverage))        
print("There have been " + str(totaltimes) + " games.")
print("The longest game took " + str(longesttotal) + " turns. The shortest took " + str(shortesttotal) + " turns.")
chessTotals = [[totalblack,totalwhite,totaldraw,overallmove, totaltimes, shortesttotal, longesttotal]]
write("chessTotals.csv", chessTotals)