Esempio n. 1
0
	void AI::PlacePiece(int(*gridArray)[3][3], sf::Sprite gridPieces[3][3], int *gameState) {
		//check if AI can win
		try {
			for (int i = 0; i < checkMatchVector.size(); i++) {
				CheckSection(checkMatchVector[i][0], checkMatchVector[i][1], checkMatchVector[i][2],
					checkMatchVector[i][3], checkMatchVector[i][4], checkMatchVector[i][5], 
					AI_PIECE, gridArray, gridPieces);
			}
			//if player can win, block that state
			for (int i = 0; i < checkMatchVector.size(); i++) {
				CheckSection(checkMatchVector[i][0], checkMatchVector[i][1], checkMatchVector[i][2],
					checkMatchVector[i][3], checkMatchVector[i][4], checkMatchVector[i][5],
					PLAYER_PIECE, gridArray, gridPieces);
			}

			//center is empty
			CheckIfPieceIsEmpty(1, 1, gridArray, gridPieces);
			//check corner
			CheckIfPieceIsEmpty(0, 2, gridArray, gridPieces);
			CheckIfPieceIsEmpty(2, 2, gridArray, gridPieces);
			CheckIfPieceIsEmpty(0, 0, gridArray, gridPieces);
			CheckIfPieceIsEmpty(2, 0, gridArray, gridPieces);

			CheckIfPieceIsEmpty(1, 2, gridArray, gridPieces);
			CheckIfPieceIsEmpty(0, 1, gridArray, gridPieces);
			CheckIfPieceIsEmpty(2, 1, gridArray, gridPieces);
			CheckIfPieceIsEmpty(1, 0, gridArray, gridPieces);
		}
		catch (int error) {

		}
		//AI turn over, player continues
		*gameState = STATE_PLAYING;
	}
Esempio n. 2
0
static
VOID
TestCreateSection(
    IN HANDLE FileHandle1,
    IN PFILE_OBJECT FileObject1,
    IN HANDLE FileHandle2,
    IN PFILE_OBJECT FileObject2)
{
    NTSTATUS Status = STATUS_SUCCESS;
    PVOID SectionObject;
    LARGE_INTEGER MaximumSize;
    ULONG PointerCount1, PointerCount2;

    KmtStartSeh()
    Status = MmCreateSection(NULL, 0, NULL, NULL, 0, SEC_RESERVE, NULL, NULL);
    KmtEndSeh(STATUS_SUCCESS);
    ok_eq_hex(Status, STATUS_INVALID_PAGE_PROTECTION);

    if (!KmtIsCheckedBuild)
    {
        /* PAGE_NOACCESS and missing SEC_RESERVE/SEC_COMMIT/SEC_IMAGE assert */
        KmtStartSeh()
        Status = MmCreateSection(NULL, 0, NULL, NULL, PAGE_NOACCESS, SEC_RESERVE, NULL, NULL);
        KmtEndSeh(STATUS_ACCESS_VIOLATION);

        KmtStartSeh()
        Status = MmCreateSection(NULL, 0, NULL, NULL, PAGE_NOACCESS, 0, NULL, NULL);
        KmtEndSeh(STATUS_ACCESS_VIOLATION);
    }

    SectionObject = KmtInvalidPointer;
    KmtStartSeh()
    Status = MmCreateSection(&SectionObject, 0, NULL, NULL, 0, SEC_RESERVE, NULL, NULL);
    KmtEndSeh(STATUS_SUCCESS);
    ok_eq_hex(Status, STATUS_INVALID_PAGE_PROTECTION);
    ok_eq_pointer(SectionObject, KmtInvalidPointer);

    if (SectionObject && SectionObject != KmtInvalidPointer)
        ObDereferenceObject(SectionObject);

    KmtStartSeh()
    Status = MmCreateSection(NULL, 0, NULL, NULL, PAGE_READONLY, SEC_RESERVE, NULL, NULL);
    KmtEndSeh(STATUS_ACCESS_VIOLATION);

    SectionObject = KmtInvalidPointer;
    KmtStartSeh()
    Status = MmCreateSection(&SectionObject, 0, NULL, NULL, PAGE_READONLY, SEC_RESERVE, NULL, NULL);
    KmtEndSeh(STATUS_ACCESS_VIOLATION);
    ok_eq_pointer(SectionObject, KmtInvalidPointer);

    if (SectionObject && SectionObject != KmtInvalidPointer)
        ObDereferenceObject(SectionObject);

    SectionObject = KmtInvalidPointer;
    MaximumSize.QuadPart = 0;
    KmtStartSeh()
    Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, NULL, NULL);
    KmtEndSeh(STATUS_SUCCESS);
    ok_eq_hex(Status, STATUS_INVALID_FILE_FOR_SECTION);
    ok_eq_longlong(MaximumSize.QuadPart, 0LL);
    ok_eq_pointer(SectionObject, KmtInvalidPointer);

    if (SectionObject && SectionObject != KmtInvalidPointer)
        ObDereferenceObject(SectionObject);

    MaximumSize.QuadPart = 0;
    KmtStartSeh()
    Status = MmCreateSection(NULL, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, NULL, NULL);
    KmtEndSeh(STATUS_SUCCESS);
    ok_eq_hex(Status, STATUS_INVALID_PARAMETER_4);
    ok_eq_longlong(MaximumSize.QuadPart, 0LL);

    if (SectionObject && SectionObject != KmtInvalidPointer)
        ObDereferenceObject(SectionObject);

    MaximumSize.QuadPart = 1;
    KmtStartSeh()
    Status = MmCreateSection(NULL, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, NULL, NULL);
    KmtEndSeh(STATUS_ACCESS_VIOLATION);
    ok_eq_longlong(MaximumSize.QuadPart, 1LL);

    if (SectionObject && SectionObject != KmtInvalidPointer)
        ObDereferenceObject(SectionObject);

    SectionObject = KmtInvalidPointer;
    MaximumSize.QuadPart = 0;
    KmtStartSeh()
    Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, NULL, NULL);
    KmtEndSeh(STATUS_SUCCESS);
    ok_eq_hex(Status, STATUS_INVALID_PARAMETER_4);
    ok_eq_longlong(MaximumSize.QuadPart, 0LL);
    ok_eq_pointer(SectionObject, KmtInvalidPointer);

    if (SectionObject && SectionObject != KmtInvalidPointer)
        ObDereferenceObject(SectionObject);

    /* page file section */
    SectionObject = KmtInvalidPointer;
    MaximumSize.QuadPart = 1;
    KmtStartSeh()
    Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, NULL, NULL);
    KmtEndSeh(STATUS_SUCCESS);
    ok_eq_hex(Status, STATUS_SUCCESS);
    ok_eq_longlong(MaximumSize.QuadPart, 1LL);
    ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
    ok(SectionObject != NULL, "Section object pointer NULL\n");

    if (SectionObject && SectionObject != KmtInvalidPointer)
        ObDereferenceObject(SectionObject);

    if (!skip(FileHandle1 != NULL && FileObject1 != NULL &&
              FileHandle2 != NULL && FileObject2 != NULL, "No file handle or object\n"))
    {
        PointerCount1 = 3;
        PointerCount2 = 3;
        /* image section */
        CheckObject(FileHandle2, PointerCount2, 1L);
        SectionObject = KmtInvalidPointer;
        MaximumSize.QuadPart = 1;
        KmtStartSeh()
        Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle2, NULL);
        KmtEndSeh(STATUS_SUCCESS);
        ok_eq_hex(Status, STATUS_SUCCESS);
        ok_eq_longlong(MaximumSize.QuadPart, 1LL);
        ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
        ok(SectionObject != NULL, "Section object pointer NULL\n");
        CheckObject(FileHandle2, PointerCount2, 1L);
        CheckSection(SectionObject, SEC_IMAGE);
        TestMapView(SectionObject, FALSE, TRUE);

        if (SectionObject && SectionObject != KmtInvalidPointer)
            ObDereferenceObject(SectionObject);

        CheckObject(FileHandle2, PointerCount2, 1L);
        SectionObject = KmtInvalidPointer;
        MaximumSize.QuadPart = 1;
        KmtStartSeh()
        Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, NULL, FileObject2);
        KmtEndSeh(STATUS_SUCCESS);
        ok_eq_hex(Status, STATUS_SUCCESS);
        ok_eq_longlong(MaximumSize.QuadPart, 1LL);
        ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
        ok(SectionObject != NULL, "Section object pointer NULL\n");
        ++PointerCount2;
        CheckObject(FileHandle2, PointerCount2, 1L);
        CheckSection(SectionObject, 0);
        TestMapView(SectionObject, TRUE, TRUE);

        if (SectionObject && SectionObject != KmtInvalidPointer)
            ObDereferenceObject(SectionObject);
        //--PointerCount2;  // ????

        CheckObject(FileHandle2, PointerCount2, 1L);
        SectionObject = KmtInvalidPointer;
        MaximumSize.QuadPart = 1;
        KmtStartSeh()
        Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle2, FileObject2);
        KmtEndSeh(STATUS_SUCCESS);
        ok_eq_hex(Status, STATUS_SUCCESS);
        ok_eq_longlong(MaximumSize.QuadPart, 1LL);
        ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
        ok(SectionObject != NULL, "Section object pointer NULL\n");
        CheckObject(FileHandle2, PointerCount2, 1L);
        CheckSection(SectionObject, 0);
        TestMapView(SectionObject, TRUE, TRUE);

        if (SectionObject && SectionObject != KmtInvalidPointer)
            ObDereferenceObject(SectionObject);

        /* image section with inappropriate file */
        CheckObject(FileHandle1, PointerCount1, 1L);
        SectionObject = KmtInvalidPointer;
        MaximumSize.QuadPart = 1;
        KmtStartSeh()
        Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle1, NULL);
        KmtEndSeh(STATUS_SUCCESS);
        ok_eq_hex(Status, STATUS_INVALID_IMAGE_NOT_MZ);
        ok_eq_longlong(MaximumSize.QuadPart, 1LL);
        ok_eq_pointer(SectionObject, KmtInvalidPointer);
        CheckObject(FileHandle1, PointerCount1, 1L);

        if (SectionObject && SectionObject != KmtInvalidPointer)
            ObDereferenceObject(SectionObject);

        CheckObject(FileHandle1, PointerCount1, 1L);
        SectionObject = KmtInvalidPointer;
        MaximumSize.QuadPart = 1;
        KmtStartSeh()
        Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, NULL, FileObject1);
        KmtEndSeh(STATUS_SUCCESS);
        ok_eq_hex(Status, STATUS_SUCCESS);
        ok_eq_longlong(MaximumSize.QuadPart, 1LL);
        ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
        ok(SectionObject != NULL, "Section object pointer NULL\n");
        ++PointerCount1;
        CheckObject(FileHandle1, PointerCount1, 1L);
        CheckSection(SectionObject, 0);
        TestMapView(SectionObject, TRUE, FALSE);

        if (SectionObject && SectionObject != KmtInvalidPointer)
            ObDereferenceObject(SectionObject);
        //--PointerCount1; // ????

        CheckObject(FileHandle1, PointerCount1, 1L);
        SectionObject = KmtInvalidPointer;
        MaximumSize.QuadPart = 1;
        KmtStartSeh()
        Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle1, FileObject1);
        KmtEndSeh(STATUS_SUCCESS);
        ok_eq_hex(Status, STATUS_SUCCESS);
        ok_eq_longlong(MaximumSize.QuadPart, 1LL);
        ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
        ok(SectionObject != NULL, "Section object pointer NULL\n");
        CheckObject(FileHandle1, PointerCount1, 1L);
        CheckSection(SectionObject, 0);
        TestMapView(SectionObject, TRUE, FALSE);

        if (SectionObject && SectionObject != KmtInvalidPointer)
            ObDereferenceObject(SectionObject);

        /* image section with two different files */
        CheckObject(FileHandle1, PointerCount1, 1L);
        SectionObject = KmtInvalidPointer;
        MaximumSize.QuadPart = 1;
        KmtStartSeh()
        Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle1, FileObject2);
        KmtEndSeh(STATUS_SUCCESS);
        ok_eq_hex(Status, STATUS_SUCCESS);
        ok_eq_longlong(MaximumSize.QuadPart, 1LL);
        ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
        ok(SectionObject != NULL, "Section object pointer NULL\n");
        CheckObject(FileHandle1, PointerCount1, 1L);
        CheckObject(FileHandle2, PointerCount2, 1L);
        CheckSection(SectionObject, 0);
        TestMapView(SectionObject, TRUE, TRUE);

        if (SectionObject && SectionObject != KmtInvalidPointer)
            ObDereferenceObject(SectionObject);

        CheckObject(FileHandle1, PointerCount1, 1L);
        SectionObject = KmtInvalidPointer;
        MaximumSize.QuadPart = 1;
        KmtStartSeh()
        Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle2, FileObject1);
        KmtEndSeh(STATUS_SUCCESS);
        ok_eq_hex(Status, STATUS_SUCCESS);
        ok_eq_longlong(MaximumSize.QuadPart, 1LL);
        ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
        ok(SectionObject != NULL, "Section object pointer NULL\n");
        CheckObject(FileHandle1, PointerCount1, 1L);
        CheckObject(FileHandle2, PointerCount2, 1L);
        CheckSection(SectionObject, 0);
        TestMapView(SectionObject, TRUE, FALSE);

        if (SectionObject && SectionObject != KmtInvalidPointer)
            ObDereferenceObject(SectionObject);

        /* data file section */
        CheckObject(FileHandle1, PointerCount1, 1L);
        SectionObject = KmtInvalidPointer;
        MaximumSize.QuadPart = 1;
        KmtStartSeh()
        Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, FileHandle1, NULL);
        KmtEndSeh(STATUS_SUCCESS);
        ok_eq_hex(Status, STATUS_SUCCESS);
        ok_eq_longlong(MaximumSize.QuadPart, 1LL);
        ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
        ok(SectionObject != NULL, "Section object pointer NULL\n");
        CheckObject(FileHandle1, PointerCount1, 1L);
        CheckSection(SectionObject, 0);
        TestMapView(SectionObject, TRUE, FALSE);

        if (SectionObject && SectionObject != KmtInvalidPointer)
            ObDereferenceObject(SectionObject);

        CheckObject(FileHandle1, PointerCount1, 1L);
        SectionObject = KmtInvalidPointer;
        MaximumSize.QuadPart = 1;
        KmtStartSeh()
        Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, NULL, FileObject1);
        KmtEndSeh(STATUS_SUCCESS);
        ok_eq_hex(Status, STATUS_SUCCESS);
        ok_eq_longlong(MaximumSize.QuadPart, 1LL);
        ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
        ok(SectionObject != NULL, "Section object pointer NULL\n");
        CheckObject(FileHandle1, PointerCount1, 1L);
        CheckSection(SectionObject, 0);
        TestMapView(SectionObject, TRUE, FALSE);

        if (SectionObject && SectionObject != KmtInvalidPointer)
            ObDereferenceObject(SectionObject);

        CheckObject(FileHandle1, PointerCount1, 1L);
        SectionObject = KmtInvalidPointer;
        MaximumSize.QuadPart = 1;
        KmtStartSeh()
        Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, FileHandle1, FileObject1);
        KmtEndSeh(STATUS_SUCCESS);
        ok_eq_hex(Status, STATUS_SUCCESS);
        ok_eq_longlong(MaximumSize.QuadPart, 1LL);
        ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
        ok(SectionObject != NULL, "Section object pointer NULL\n");
        CheckObject(FileHandle1, PointerCount1, 1L);
        CheckSection(SectionObject, 0);
        TestMapView(SectionObject, TRUE, FALSE);

        if (SectionObject && SectionObject != KmtInvalidPointer)
            ObDereferenceObject(SectionObject);

        CheckObject(FileHandle1, PointerCount1, 1L);
    }
}